1 Star 0 Fork 204

Jason/goAdapter

forked from shiyin1211/openGW 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
routerSerial.go 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
shiyin1211 提交于 2020-06-28 18:15 . 创建工程
package main
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
func apiSetSerial(context *gin.Context){
aParam := struct{
Code string `json:"Code"`
Message string `json:"Message"`
Data string `json:"Data"`
}{
Code:"1",
Message:"",
Data:"",
}
bodyBuf := make([]byte,1024)
n,_ := context.Request.Body.Read(bodyBuf)
fmt.Println(string(bodyBuf[:n]))
//获取写寄存器的参数
rSerialParam := &SerialParamTemplate{
}
err := json.Unmarshal(bodyBuf[:n],rSerialParam)
if err != nil {
fmt.Println("rSerialParam json unMarshall err,",err)
aParam.Code = "1"
aParam.Message = "json unMarshall err"
sJson,_ := json.Marshal(aParam)
context.String(http.StatusOK,string(sJson))
return
}
for k,v := range serialInterface.SerialParam{
if v.ID == rSerialParam.ID{
serialInterface.SerialParam[k] = *rSerialParam
serialParaWrite()
}else{
aParam.Code = "1"
aParam.Message = "serial ID is not exist"
sJson,_ := json.Marshal(aParam)
context.String(http.StatusOK,string(sJson))
return
}
}
aParam.Code = "0"
sJson,_ := json.Marshal(aParam)
context.String(http.StatusOK,string(sJson))
}
func apiGetSerial(context *gin.Context){
aParam := struct{
Code string `json:"Code"`
Message string `json:"Message"`
Data SerialInterface `json:"Data"`
}{Code:"0"}
aParam.Data = serialInterface
sJson,_ := json.Marshal(aParam)
context.String(http.StatusOK,string(sJson))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lghtjpu/goAdapter.git
git@gitee.com:lghtjpu/goAdapter.git
lghtjpu
goAdapter
goAdapter
master

搜索帮助