67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/gin"
|
|
"go_dreamfactory/lego/sys/gin/engine"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type SyncCrossReq struct {
|
|
Timestamp string `json:"timestamp"`
|
|
Sign string `json:"sign"`
|
|
}
|
|
type SyncCrossResp struct {
|
|
Code int32 `json:"code"`
|
|
Message string `json:"msg"`
|
|
Data string `json:"data"`
|
|
}
|
|
|
|
//同步跨服列表
|
|
func (this *Api_Comp) SyncCross(c *engine.Context) {
|
|
var (
|
|
req *SyncCrossReq = &SyncCrossReq{}
|
|
resp *SyncCrossResp = &SyncCrossResp{}
|
|
err error
|
|
)
|
|
defer c.JSON(http.StatusOK, resp)
|
|
if err = c.BindJSON(req); err != nil {
|
|
resp.Code = int32(pb.ErrorCode_ReqParameterError)
|
|
resp.Message = pb.GetErrorCodeMsg(pb.ErrorCode_ReqParameterError)
|
|
return
|
|
}
|
|
if sign := gin.ParamSign(this.options.Key, map[string]interface{}{
|
|
"timestamp": req.Timestamp,
|
|
}); sign != req.Sign {
|
|
this.module.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
|
resp.Code = int32(pb.ErrorCode_SignError)
|
|
resp.Message = pb.GetErrorCodeMsg(pb.ErrorCode_SignError)
|
|
return
|
|
}
|
|
if !db.IsCross() {
|
|
resp.Code = int32(pb.ErrorCode_ReqParameterError)
|
|
resp.Message = "curr service is not cross!"
|
|
return
|
|
}
|
|
if err = db.SyncServiceList(); err != nil {
|
|
resp.Code = int32(pb.ErrorCode_ReqParameterError)
|
|
resp.Message = err.Error()
|
|
return
|
|
}
|
|
ctx, _ := context.WithTimeout(context.TODO(), time.Second*5)
|
|
if err = this.module.service.RpcBroadcast(
|
|
ctx,
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_DBSyncCross),
|
|
pb.EmptyReq{},
|
|
pb.EmptyResp{}); err != nil {
|
|
this.module.Errorln(err)
|
|
resp.Code = int32(pb.ErrorCode_RpcFuncExecutionError)
|
|
resp.Message = err.Error()
|
|
}
|
|
}
|