diff --git a/controller/unis/commonser.go b/controller/unis/commonser.go index 33d2cd5..cab78bb 100644 --- a/controller/unis/commonser.go +++ b/controller/unis/commonser.go @@ -1,68 +1,27 @@ package unis import ( - "bytes" - "dashboard/dao/sqldb" "dashboard/models" "dashboard/services/unis" - "encoding/json" - "fmt" - "io" "net/http" - "reflect" - "strconv" "github.com/gin-gonic/gin" ) func StationConfig(c *gin.Context) error { - bodyBytes, err := io.ReadAll(c.Request.Body) - if err != nil { - return err - } - - c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) - var config models.StationConfigParams if err := c.ShouldBindJSON(&config); err != nil { return err } - // serverId := c.GetHeader("serverId") - channelStr := c.GetHeader("channel") - channel, err := strconv.Atoi(channelStr) - if err != nil { + if err := unis.StationConfig(&config); err != nil { return err } - fmt.Println("url", c.Request.URL.String()) - - oldConf, err := sqldb.ResFulDataGet(c.Request.Method, c.Request.URL.String(), channel) - if err != nil { - return err - } - - var oldconfig models.StationConfigParams - if oldConf != "" { - if err := json.Unmarshal([]byte(oldConf), &oldconfig); err != nil { - return err - } - } - - oldconfig.StationConfig.ConfigType = config.StationConfig.ConfigType - - if !reflect.DeepEqual(config, oldconfig) { - fmt.Println("config is not equal") - if err := sqldb.ResFulDataStore(c.Request.Method, c.Request.URL.RawPath, string(bodyBytes), channel); err != nil { - return err - } - } - - if err:=unis.StationConfig(&config);err!=nil{ - return err - } - - c.JSON(http.StatusOK, "ok") + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "msg": "Server station config ok", + }) return nil } diff --git a/models/type.go b/models/type.go index 6e3d2e7..d9d3a70 100644 --- a/models/type.go +++ b/models/type.go @@ -6,7 +6,9 @@ import ( ) const ( - GinContxtLog = "log" + GinContextLog = "log" + GinContextChannel = "channel" + GinContextServerId = "serverid" ) const ( diff --git a/models/unisrpcparams.go b/models/unisrpcparams.go index 283e34f..34c5161 100644 --- a/models/unisrpcparams.go +++ b/models/unisrpcparams.go @@ -6,7 +6,7 @@ const rpcNamePrefix = "UnisRpcService" type UnisRpcMethod string -func (m UnisRpcMethod)String()string{ +func (m UnisRpcMethod)Methord()string{ return fmt.Sprintf("%s.%s",rpcNamePrefix,string(m)) } diff --git a/routes/middleware.go b/routes/middleware.go index 53a4299..c018e19 100644 --- a/routes/middleware.go +++ b/routes/middleware.go @@ -96,7 +96,7 @@ func GinRecovery(log *logger.Logger, stack bool) gin.HandlerFunc { func GinLog(log *logger.Logger) gin.HandlerFunc { return func(c *gin.Context) { - c.Set(models.GinContxtLog, log) + c.Set(models.GinContextLog, log) c.Next() } } @@ -172,6 +172,18 @@ func GinCheckServerId(c *gin.Context) error { } } + channel, err := strconv.Atoi(c.GetHeader("channel")) + if err != nil { + c.Abort() + return &models.BaseError{ + Code: http.StatusServiceUnavailable, + Msg: "Channel Id error", + } + } + + c.Set(models.GinContextServerId, serverId) + c.Set(models.GinContextChannel, channel) + c.Next() return nil @@ -188,15 +200,7 @@ func GinStoreRequest(c *gin.Context) (err error) { }() log, _ := utils.GetLogFromContext(c) - - channel, _err := strconv.Atoi(c.GetHeader("channel")) - if _err != nil { - err = &models.BaseError{ - Code: http.StatusServiceUnavailable, - Msg: "Channel Id error", - } - return - } + channel := c.GetInt(models.GinContextChannel) oldConf, _err := sqldb.ResFulDataGet(c.Request.Method, c.Request.URL.String(), channel) if _err != nil { diff --git a/services/unis/rpcclient.go b/services/unis/rpcclient.go index 7166ed5..d1c4fc0 100644 --- a/services/unis/rpcclient.go +++ b/services/unis/rpcclient.go @@ -10,7 +10,7 @@ func GetConfig(req models.UnisRpcRequest) (*models.UnisRpcResponse, error) { for key, value := range rpcMapClients { fmt.Println(key) - value.Call(models.UnisStationConfig.String(), req, out) + value.Call(models.UnisStationConfig.Methord(), req, out) } return out, nil diff --git a/utils/gin.go b/utils/gin.go index 42b1022..265b37b 100644 --- a/utils/gin.go +++ b/utils/gin.go @@ -8,7 +8,7 @@ import ( ) func GetLogFromContext(c *gin.Context) (*logger.Logger, error) { - res, ok := c.Get(models.GinContxtLog) + res, ok := c.Get(models.GinContextLog) if !ok { return nil, models.ErrorInvalidData }