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 { 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") return nil }