修改:1、gin中代码结构改成mvc模式
This commit is contained in:
parent
d25943e21e
commit
3e84eda51c
Binary file not shown.
|
@ -1,4 +1,4 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"goAdapter/device/commInterface"
|
||||
"goAdapter/httpServer/model"
|
||||
"goAdapter/setting"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -20,7 +21,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiAddInterface(context *gin.Context) {
|
||||
func ApiAddInterface(context *gin.Context) {
|
||||
interfaceInfo := &struct {
|
||||
CollectInterfaceName string `json:"CollInterfaceName"` // 采集接口名字
|
||||
CommInterfaceName string `json:"CommInterfaceName"` // 通信接口名字
|
||||
|
@ -32,7 +33,7 @@ func apiAddInterface(context *gin.Context) {
|
|||
if err != nil {
|
||||
fmt.Println("interfaceInfo json unMarshall err,", err)
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "json unMarshall err",
|
||||
})
|
||||
|
@ -44,21 +45,21 @@ func apiAddInterface(context *gin.Context) {
|
|||
interfaceInfo.PollPeriod,
|
||||
interfaceInfo.OfflinePeriod)
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
})
|
||||
}
|
||||
|
||||
func apiModifyInterface(context *gin.Context) {
|
||||
func ApiModifyInterface(context *gin.Context) {
|
||||
|
||||
aParam := Response{
|
||||
aParam := model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -105,9 +106,9 @@ func apiModifyInterface(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiDeleteInterface(context *gin.Context) {
|
||||
func ApiDeleteInterface(context *gin.Context) {
|
||||
|
||||
aParam := Response{
|
||||
aParam := model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -149,7 +150,7 @@ func apiDeleteInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetInterfaceInfo(context *gin.Context) {
|
||||
func ApiGetInterfaceInfo(context *gin.Context) {
|
||||
|
||||
//采集接口模板
|
||||
type CollectInterfaceTemplate struct {
|
||||
|
@ -199,7 +200,7 @@ func apiGetInterfaceInfo(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiGetAllInterfaceInfo(context *gin.Context) {
|
||||
func ApiGetAllInterfaceInfo(context *gin.Context) {
|
||||
|
||||
type InterfaceParamTemplate struct {
|
||||
CollInterfaceName string `json:"CollInterfaceName"` // 采集接口
|
||||
|
@ -242,9 +243,9 @@ func apiGetAllInterfaceInfo(context *gin.Context) {
|
|||
context.JSON(http.StatusOK, aParam)
|
||||
}
|
||||
|
||||
func apiAddNode(context *gin.Context) {
|
||||
func ApiAddNode(context *gin.Context) {
|
||||
|
||||
aParam := Response{
|
||||
aParam := model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -302,7 +303,7 @@ func apiAddNode(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiModifyNode(context *gin.Context) {
|
||||
func ApiModifyNode(context *gin.Context) {
|
||||
|
||||
type DeleteAck struct {
|
||||
Name string
|
||||
|
@ -370,7 +371,7 @@ func apiModifyNode(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiModifyNodes(context *gin.Context) {
|
||||
func ApiModifyNodes(context *gin.Context) {
|
||||
|
||||
type DeleteAck struct {
|
||||
Name string
|
||||
|
@ -442,7 +443,7 @@ func apiModifyNodes(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetNode(context *gin.Context) {
|
||||
func ApiGetNode(context *gin.Context) {
|
||||
|
||||
sName := context.Query("CollInterfaceName")
|
||||
sAddr := context.Query("Addr")
|
||||
|
@ -475,7 +476,7 @@ func apiGetNode(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiDeleteNode(context *gin.Context) {
|
||||
func ApiDeleteNode(context *gin.Context) {
|
||||
|
||||
type DeleteAck struct {
|
||||
Name string
|
||||
|
@ -554,7 +555,7 @@ func apiDeleteNode(context *gin.Context) {
|
|||
/**
|
||||
从缓存中获取设备变量
|
||||
*/
|
||||
func apiGetNodeVariableFromCache(context *gin.Context) {
|
||||
func ApiGetNodeVariableFromCache(context *gin.Context) {
|
||||
|
||||
type VariableTemplate struct {
|
||||
Index int `json:"index"` // 变量偏移量
|
||||
|
@ -626,7 +627,7 @@ func apiGetNodeVariableFromCache(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiGetNodeHistoryVariableFromCache(context *gin.Context) {
|
||||
func ApiGetNodeHistoryVariableFromCache(context *gin.Context) {
|
||||
|
||||
sName := context.Query("CollInterfaceName")
|
||||
sAddr := context.Query("Addr")
|
||||
|
@ -665,7 +666,7 @@ func apiGetNodeHistoryVariableFromCache(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiGetNodeReadVariable(context *gin.Context) {
|
||||
func ApiGetNodeReadVariable(context *gin.Context) {
|
||||
|
||||
type VariableTemplate struct {
|
||||
Index int `json:"index"` // 变量偏移量
|
||||
|
@ -754,7 +755,7 @@ func apiGetNodeReadVariable(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiAddDeviceTSL(context *gin.Context) {
|
||||
func ApiAddDeviceTSL(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -806,7 +807,7 @@ func apiAddDeviceTSL(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteDeviceTSL(context *gin.Context) {
|
||||
func ApiDeleteDeviceTSL(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -856,7 +857,7 @@ func apiDeleteDeviceTSL(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiModifyDeviceTSL(context *gin.Context) {
|
||||
func ApiModifyDeviceTSL(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -916,7 +917,7 @@ func apiModifyDeviceTSL(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetDeviceTSL(context *gin.Context) {
|
||||
func ApiGetDeviceTSL(context *gin.Context) {
|
||||
|
||||
type TSLInfoTemplate struct {
|
||||
Name string
|
||||
|
@ -950,7 +951,7 @@ func apiGetDeviceTSL(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetDeviceTSLContents(context *gin.Context) {
|
||||
func ApiGetDeviceTSLContents(context *gin.Context) {
|
||||
|
||||
type DeviceTSLPropertyIntUintParamTempate struct {
|
||||
Min string `json:"Min"` //最小
|
||||
|
@ -1070,7 +1071,7 @@ func apiGetDeviceTSLContents(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiImportDeviceTSLContents(context *gin.Context) {
|
||||
func ApiImportDeviceTSLContents(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1209,7 +1210,7 @@ func apiImportDeviceTSLContents(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiExportDeviceTSLContents(context *gin.Context) {
|
||||
func ApiExportDeviceTSLContents(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1332,7 +1333,7 @@ func apiExportDeviceTSLContents(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
func apiExportDeviceTSLContentsTemplate(context *gin.Context) {
|
||||
func ApiExportDeviceTSLContentsTemplate(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1386,7 +1387,7 @@ func apiExportDeviceTSLContentsTemplate(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
func apiImportDeviceTSLPlugin(context *gin.Context) {
|
||||
func ApiImportDeviceTSLPlugin(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1460,7 +1461,7 @@ func apiImportDeviceTSLPlugin(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiExportDeviceTSLPlugin(context *gin.Context) {
|
||||
func ApiExportDeviceTSLPlugin(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1496,7 +1497,7 @@ func apiExportDeviceTSLPlugin(context *gin.Context) {
|
|||
context.File(name) //返回文件路径,自动调用http.ServeFile方法
|
||||
|
||||
} else {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -1504,7 +1505,7 @@ func apiExportDeviceTSLPlugin(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiAddDeviceTSLProperty(context *gin.Context) {
|
||||
func ApiAddDeviceTSLProperty(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1561,7 +1562,7 @@ func apiAddDeviceTSLProperty(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiModifyDeviceTSLProperty(context *gin.Context) {
|
||||
func ApiModifyDeviceTSLProperty(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1618,7 +1619,7 @@ func apiModifyDeviceTSLProperty(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteDeviceTSLProperties(context *gin.Context) {
|
||||
func ApiDeleteDeviceTSLProperties(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1688,7 +1689,7 @@ func apiDeleteDeviceTSLProperties(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetDeviceTSLProperties(context *gin.Context) {
|
||||
func ApiGetDeviceTSLProperties(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1721,7 +1722,7 @@ func apiGetDeviceTSLProperties(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiAddDeviceTSLService(context *gin.Context) {
|
||||
func ApiAddDeviceTSLService(context *gin.Context) {
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
|
@ -1777,7 +1778,7 @@ func apiAddDeviceTSLService(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiModifyDeviceTSLService(context *gin.Context) {
|
||||
func ApiModifyDeviceTSLService(context *gin.Context) {
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
|
@ -1833,7 +1834,7 @@ func apiModifyDeviceTSLService(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteDeviceTSLServices(context *gin.Context) {
|
||||
func ApiDeleteDeviceTSLServices(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -1903,7 +1904,7 @@ func apiDeleteDeviceTSLServices(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiAddCommInterface(context *gin.Context) {
|
||||
func ApiAddCommInterface(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -2087,7 +2088,7 @@ func apiAddCommInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiModifyCommInterface(context *gin.Context) {
|
||||
func ApiModifyCommInterface(context *gin.Context) {
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
|
@ -2267,7 +2268,7 @@ func apiModifyCommInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteCommInterface(context *gin.Context) {
|
||||
func ApiDeleteCommInterface(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -2359,7 +2360,7 @@ func apiDeleteCommInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetCommInterface(context *gin.Context) {
|
||||
func ApiGetCommInterface(context *gin.Context) {
|
||||
|
||||
type CommunicationInterfaceTemplate struct {
|
||||
Name string `json:"Name"` // 接口名称
|
||||
|
@ -2447,7 +2448,7 @@ func apiGetCommInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiAddCommSerialInterface(context *gin.Context) {
|
||||
func ApiAddCommSerialInterface(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -2508,7 +2509,7 @@ func apiAddCommSerialInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiModifyCommSerialInterface(context *gin.Context) {
|
||||
func ApiModifyCommSerialInterface(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -2564,7 +2565,7 @@ func apiModifyCommSerialInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteCommSerialInterface(context *gin.Context) {
|
||||
func ApiDeleteCommSerialInterface(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -2618,7 +2619,7 @@ func apiDeleteCommSerialInterface(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiInvokeService(context *gin.Context) {
|
||||
func ApiInvokeService(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -2681,7 +2682,7 @@ func apiInvokeService(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiSendDirectDataToCollInterface(context *gin.Context) {
|
||||
func ApiSendDirectDataToCollInterface(context *gin.Context) {
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
|
@ -1,4 +1,4 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiGetLogParam(context *gin.Context) {
|
||||
func ApiGetLogParam(context *gin.Context) {
|
||||
|
||||
aParam := &struct {
|
||||
Code string
|
||||
|
@ -29,7 +29,7 @@ func apiGetLogParam(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
func apiSetLogParam(context *gin.Context) {
|
||||
func ApiSetLogParam(context *gin.Context) {
|
||||
|
||||
aParam := &struct {
|
||||
Code string
|
||||
|
@ -66,7 +66,7 @@ func apiSetLogParam(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
func apiGetLogFilesInfo(context *gin.Context) {
|
||||
func ApiGetLogFilesInfo(context *gin.Context) {
|
||||
|
||||
aParam := &struct {
|
||||
Code string
|
||||
|
@ -100,7 +100,7 @@ func apiGetLogFilesInfo(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteLogFile(context *gin.Context) {
|
||||
func ApiDeleteLogFile(context *gin.Context) {
|
||||
aParam := &struct {
|
||||
Code string
|
||||
Message string
|
||||
|
@ -161,7 +161,7 @@ func apiDeleteLogFile(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
func apiGetLogFile(context *gin.Context) {
|
||||
func ApiGetLogFile(context *gin.Context) {
|
||||
|
||||
aParam := &struct {
|
||||
Code string
|
|
@ -1,8 +1,9 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"goAdapter/httpServer/model"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -73,14 +74,14 @@ func mbParamWriteMutilReg(slaveAddr byte, regAddr uint16, regCnt uint16, data []
|
|||
return err
|
||||
}
|
||||
|
||||
func apiReadHoldReg(context *gin.Context) {
|
||||
func ApiReadHoldReg(context *gin.Context) {
|
||||
//获取读寄存器的参数
|
||||
rMbParam := &MbParam{}
|
||||
err := context.ShouldBindJSON(rMbParam)
|
||||
if err != nil {
|
||||
fmt.Println("rMbParam json unMarshall err,", err)
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "json unMarshall err",
|
||||
})
|
||||
|
@ -102,21 +103,21 @@ func apiReadHoldReg(context *gin.Context) {
|
|||
}
|
||||
fmt.Println(sRegValue)
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: sRegValue,
|
||||
})
|
||||
}
|
||||
|
||||
func apiWriteMultiReg(context *gin.Context) {
|
||||
func ApiWriteMultiReg(context *gin.Context) {
|
||||
//获取写寄存器的参数
|
||||
rMbParam := &MbParam{}
|
||||
err := context.ShouldBindJSON(rMbParam)
|
||||
if err != nil {
|
||||
fmt.Println("rMbParam json unMarshall err,", err)
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "json unMarshall err",
|
||||
Data: "",
|
||||
|
@ -141,14 +142,14 @@ func apiWriteMultiReg(context *gin.Context) {
|
|||
err = mbParamWriteMutilReg(rMbParam.Addr, rMbParam.RegAddr,
|
||||
rMbParam.RegCnt, bData)
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "write reg timeout",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
|
@ -1,13 +1,15 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"goAdapter/httpServer/model"
|
||||
"goAdapter/setting"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiAddNetwork(context *gin.Context) {
|
||||
func ApiAddNetwork(context *gin.Context) {
|
||||
type NetworkSetParamTemplate struct {
|
||||
Name string `json:"Name"`
|
||||
DHCP string `json:"DHCP"`
|
||||
|
@ -21,7 +23,7 @@ func apiAddNetwork(context *gin.Context) {
|
|||
err := context.ShouldBindJSON(&networkParam)
|
||||
if err != nil {
|
||||
setting.Logger.Warnf("rNetworkParam json unMarshall err,", err)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -39,13 +41,13 @@ func apiAddNetwork(context *gin.Context) {
|
|||
|
||||
err = setting.NetworkParamList.AddNetworkParam(param)
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: err.Error(),
|
||||
Data: "",
|
||||
})
|
||||
} else {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -53,7 +55,7 @@ func apiAddNetwork(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiModifyNetwork(context *gin.Context) {
|
||||
func ApiModifyNetwork(context *gin.Context) {
|
||||
type NetworkSetParamTemplate struct {
|
||||
Name string `json:"Name"`
|
||||
DHCP string `json:"DHCP"`
|
||||
|
@ -67,7 +69,7 @@ func apiModifyNetwork(context *gin.Context) {
|
|||
err := context.ShouldBindJSON(&networkParam)
|
||||
if err != nil {
|
||||
fmt.Println("rNetworkParam json unMarshall err,", err)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -84,14 +86,14 @@ func apiModifyNetwork(context *gin.Context) {
|
|||
}
|
||||
|
||||
setting.NetworkParamList.ModifyNetworkParam(param)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
})
|
||||
}
|
||||
|
||||
func apiDeleteNetwork(context *gin.Context) {
|
||||
func ApiDeleteNetwork(context *gin.Context) {
|
||||
type NetworkSetParamTemplate struct {
|
||||
Name string `json:"Name"`
|
||||
}
|
||||
|
@ -101,7 +103,7 @@ func apiDeleteNetwork(context *gin.Context) {
|
|||
err := context.ShouldBindJSON(&networkParam)
|
||||
if err != nil {
|
||||
fmt.Println("rNetworkParam json unMarshall err,", err)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -111,13 +113,13 @@ func apiDeleteNetwork(context *gin.Context) {
|
|||
|
||||
status, _ := setting.NetworkParamList.DeleteNetworkParam(networkParam.Name)
|
||||
if status == true {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
})
|
||||
} else {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "网络名称不存在",
|
||||
Data: "",
|
||||
|
@ -126,14 +128,14 @@ func apiDeleteNetwork(context *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func apiGetNetwork(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiGetNetwork(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "0",
|
||||
Data: *setting.NetworkParamList,
|
||||
})
|
||||
}
|
||||
|
||||
func apiGetNetworkLinkState(context *gin.Context) {
|
||||
func ApiGetNetworkLinkState(context *gin.Context) {
|
||||
// context.JSON(http.StatusOK, ResponseData{
|
||||
// Code: "0",
|
||||
// Data: setting.NetworkLinkState,
|
|
@ -1,4 +1,4 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiSetReportGWParam(context *gin.Context) {
|
||||
func ApiSetReportGWParam(context *gin.Context) {
|
||||
|
||||
type ReportServiceTemplate struct {
|
||||
ServiceName string
|
||||
|
@ -94,7 +94,7 @@ func apiSetReportGWParam(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetReportGWParam(context *gin.Context) {
|
||||
func ApiGetReportGWParam(context *gin.Context) {
|
||||
|
||||
type ReportServiceTemplate struct {
|
||||
ServiceName string
|
||||
|
@ -164,7 +164,7 @@ func apiGetReportGWParam(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteReportGWParam(context *gin.Context) {
|
||||
func ApiDeleteReportGWParam(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
||||
|
@ -248,7 +248,7 @@ func apiDeleteReportGWParam(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiSetReportNodeWParam(context *gin.Context) {
|
||||
func ApiSetReportNodeWParam(context *gin.Context) {
|
||||
|
||||
type ReportServiceNodeTemplate struct {
|
||||
ServiceName string
|
||||
|
@ -344,7 +344,7 @@ func apiSetReportNodeWParam(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiBatchAddReportNodeParam(context *gin.Context) {
|
||||
func ApiBatchAddReportNodeParam(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string
|
||||
|
@ -414,7 +414,7 @@ func apiBatchAddReportNodeParam(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetReportNodeWParam(context *gin.Context) {
|
||||
func ApiGetReportNodeWParam(context *gin.Context) {
|
||||
|
||||
type ReportServiceNodeTemplate struct {
|
||||
ServiceName string
|
||||
|
@ -509,7 +509,7 @@ func apiGetReportNodeWParam(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiDeleteReportNodeWParam(context *gin.Context) {
|
||||
func ApiDeleteReportNodeWParam(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
Code string `json:"Code"`
|
|
@ -1,6 +1,7 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"goAdapter/httpServer/model"
|
||||
"net/http"
|
||||
|
||||
"goAdapter/setting"
|
||||
|
@ -8,7 +9,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiGetSerial(context *gin.Context) {
|
||||
func ApiGetSerial(context *gin.Context) {
|
||||
type SerialPortNameTemplate struct {
|
||||
Name string `json:"Name"`
|
||||
}
|
||||
|
@ -21,7 +22,7 @@ func apiGetSerial(context *gin.Context) {
|
|||
data = append(data, SerialPortName)
|
||||
}
|
||||
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: data,
|
|
@ -1,7 +1,9 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"goAdapter/httpServer/middleware"
|
||||
"goAdapter/httpServer/model"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -11,8 +13,8 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiSystemReboot(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
func ApiSystemReboot(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -21,39 +23,39 @@ func apiSystemReboot(context *gin.Context) {
|
|||
setting.SystemReboot()
|
||||
}
|
||||
|
||||
func apiGetSystemStatus(context *gin.Context) {
|
||||
func ApiGetSystemStatus(context *gin.Context) {
|
||||
|
||||
setting.GetMemState()
|
||||
setting.GetDiskState()
|
||||
setting.GetRunTime()
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
"0",
|
||||
"",
|
||||
setting.SystemState,
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemLoginParam(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiSystemLoginParam(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
"0",
|
||||
"",
|
||||
loginResult,
|
||||
middleware.LoginResult,
|
||||
})
|
||||
}
|
||||
|
||||
// 定义登陆逻辑
|
||||
// model.LoginReq中定义了登陆的请求体(name,passwd)
|
||||
func apiLogin(c *gin.Context) {
|
||||
var loginReq LoginReq
|
||||
func ApiLogin(c *gin.Context) {
|
||||
var loginReq middleware.LoginReq
|
||||
if c.BindJSON(&loginReq) == nil {
|
||||
// 登陆逻辑校验(查库,验证用户是否存在以及登陆信息是否正确)
|
||||
isPass, user, err := LoginCheck(loginReq)
|
||||
isPass, user, err := middleware.LoginCheck(loginReq)
|
||||
// 验证通过后为该次请求生成token
|
||||
if isPass {
|
||||
generateToken(c, user)
|
||||
middleware.GenerateToken(c, user)
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Code": "-1",
|
||||
"Code": "1",
|
||||
"Message": "验证失败" + err.Error(),
|
||||
"Data": "",
|
||||
})
|
||||
|
@ -62,7 +64,7 @@ func apiLogin(c *gin.Context) {
|
|||
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Code": "-1",
|
||||
"Code": "1",
|
||||
"Message": "用户数据解析失败",
|
||||
"Data": "",
|
||||
})
|
||||
|
@ -70,46 +72,46 @@ func apiLogin(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiSystemMemoryUseList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiSystemMemoryUseList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
"0",
|
||||
"",
|
||||
*setting.MemoryDataStream,
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemDiskUseList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiSystemDiskUseList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
"0",
|
||||
"",
|
||||
*setting.DiskDataStream,
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemDeviceOnlineList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiSystemDeviceOnlineList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
"0",
|
||||
"",
|
||||
*setting.DeviceOnlineDataStream,
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemDevicePacketLossList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiSystemDevicePacketLossList(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
"0",
|
||||
"",
|
||||
*setting.DevicePacketLossDataStream,
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemSetSystemRTC(context *gin.Context) {
|
||||
func ApiSystemSetSystemRTC(context *gin.Context) {
|
||||
rRTC := &struct {
|
||||
SystemRTC string `json:"systemRTC"`
|
||||
}{}
|
||||
err := context.ShouldBindJSON(rRTC)
|
||||
if err != nil {
|
||||
fmt.Println("rRTC json unMarshall err,", err)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "json unMarshall err",
|
||||
Data: "",
|
||||
|
@ -118,14 +120,14 @@ func apiSystemSetSystemRTC(context *gin.Context) {
|
|||
}
|
||||
setting.Logger.Debugf("systemRTC %v", rRTC)
|
||||
setting.SystemSetRTC(rRTC.SystemRTC)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemSetNTPHost(context *gin.Context) {
|
||||
func ApiSystemSetNTPHost(context *gin.Context) {
|
||||
|
||||
rNTPHostAddr := setting.NTPHostAddrTemplate{}
|
||||
|
||||
|
@ -133,7 +135,7 @@ func apiSystemSetNTPHost(context *gin.Context) {
|
|||
if err != nil {
|
||||
fmt.Println("rNTPHostAddr json unMarshall err,", err)
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "json unMarshall err",
|
||||
Data: "",
|
||||
|
@ -143,22 +145,22 @@ func apiSystemSetNTPHost(context *gin.Context) {
|
|||
|
||||
setting.NTPHostAddr = rNTPHostAddr
|
||||
setting.WriteNTPHostAddrToJson()
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
})
|
||||
}
|
||||
|
||||
func apiSystemGetNTPHost(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
func ApiSystemGetNTPHost(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: setting.NTPHostAddr,
|
||||
})
|
||||
}
|
||||
|
||||
func apiBackupFiles(context *gin.Context) {
|
||||
func ApiBackupFiles(context *gin.Context) {
|
||||
|
||||
status, name := setting.BackupFiles()
|
||||
if status == true {
|
||||
|
@ -168,7 +170,7 @@ func apiBackupFiles(context *gin.Context) {
|
|||
context.File(name) //返回文件路径,自动调用http.ServeFile方法
|
||||
|
||||
} else {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -176,12 +178,12 @@ func apiBackupFiles(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiRecoverFiles(context *gin.Context) {
|
||||
func ApiRecoverFiles(context *gin.Context) {
|
||||
|
||||
// 获取文件头
|
||||
file, err := context.FormFile("file")
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -194,7 +196,7 @@ func apiRecoverFiles(context *gin.Context) {
|
|||
|
||||
//保存文件到服务器本地
|
||||
if err := context.SaveUploadedFile(file, fileName); err != nil {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "Save File Error",
|
||||
Data: "",
|
||||
|
@ -206,13 +208,13 @@ func apiRecoverFiles(context *gin.Context) {
|
|||
//恢复
|
||||
status := setting.RecoverFiles(file.Filename)
|
||||
if status == true {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
||||
})
|
||||
} else {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -220,12 +222,12 @@ func apiRecoverFiles(context *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiSystemUpdate(context *gin.Context) {
|
||||
func ApiSystemUpdate(context *gin.Context) {
|
||||
|
||||
// 获取文件头
|
||||
file, err := context.FormFile("file")
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -238,7 +240,7 @@ func apiSystemUpdate(context *gin.Context) {
|
|||
|
||||
//保存文件到服务器本地
|
||||
if err := context.SaveUploadedFile(file, fileName); err != nil {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "1",
|
||||
Message: "Save File Error",
|
||||
Data: "",
|
||||
|
@ -249,7 +251,7 @@ func apiSystemUpdate(context *gin.Context) {
|
|||
//升级文件解析
|
||||
status := setting.Update(file.Filename)
|
||||
if status == true {
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "0",
|
||||
Message: "",
|
||||
Data: "",
|
|
@ -1,14 +1,15 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"goAdapter/device"
|
||||
"goAdapter/httpServer/model"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func apiGetCommMessage(context *gin.Context) {
|
||||
func ApiGetCommMessage(context *gin.Context) {
|
||||
interfaceName := struct {
|
||||
CollInterfaceNames []string `json:"CollInterfaceNames"` //接口名称
|
||||
}{}
|
||||
|
@ -19,7 +20,7 @@ func apiGetCommMessage(context *gin.Context) {
|
|||
if err != nil {
|
||||
fmt.Println("interfaceInfo json unMarshall err,", err)
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "json unMarshall err",
|
||||
})
|
||||
|
@ -35,7 +36,7 @@ func apiGetCommMessage(context *gin.Context) {
|
|||
// 清空map
|
||||
coll.CommQueueManage.CommMessage = coll.CommQueueManage.CommMessage[0:0]
|
||||
}
|
||||
context.JSON(http.StatusOK, ResponseData{
|
||||
context.JSON(http.StatusOK, model.ResponseData{
|
||||
Code: "0",
|
||||
Data: commMessageMap,
|
||||
})
|
|
@ -1,7 +1,8 @@
|
|||
package httpServer
|
||||
package contorl
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"goAdapter/httpServer/model"
|
||||
"goAdapter/setting"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -61,12 +62,12 @@ func unZip(zipFile string, destDir string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func apiUpdatePlugin(context *gin.Context) {
|
||||
func ApiUpdatePlugin(context *gin.Context) {
|
||||
|
||||
// 获取文件头
|
||||
file, err := context.FormFile("file")
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "",
|
||||
Data: "",
|
||||
|
@ -87,7 +88,7 @@ func apiUpdatePlugin(context *gin.Context) {
|
|||
//保存文件到服务器本地
|
||||
if err := context.SaveUploadedFile(file, fileName); err != nil {
|
||||
log.Println(err)
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "1",
|
||||
Message: "save error",
|
||||
})
|
||||
|
@ -100,7 +101,7 @@ func apiUpdatePlugin(context *gin.Context) {
|
|||
setting.Logger.Errorf("removeFile err,%s\n", fileName)
|
||||
}
|
||||
|
||||
context.JSON(http.StatusOK, Response{
|
||||
context.JSON(http.StatusOK, model.Response{
|
||||
Code: "0",
|
||||
Message: "save sucess",
|
||||
})
|
|
@ -1,13 +1,14 @@
|
|||
package httpServer
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"goAdapter/setting"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 定义一个jwt对象
|
||||
|
@ -16,13 +17,6 @@ type JWT struct {
|
|||
SigningKey []byte
|
||||
}
|
||||
|
||||
// 初始化jwt对象
|
||||
func NewJWT() *JWT {
|
||||
return &JWT{
|
||||
[]byte("bgbiao.top"),
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义有效载荷(这里采用自定义的Name和Email作为有效载荷的一部分)
|
||||
type CustomClaims struct {
|
||||
Name string `json:"name"`
|
||||
|
@ -33,13 +27,13 @@ type CustomClaims struct {
|
|||
|
||||
// 构造用户表
|
||||
type User struct {
|
||||
Id int32 `gorm:"AUTO_INCREMENT"`
|
||||
Name string `json:"username"`
|
||||
Pwd string `json:"password"`
|
||||
Phone int64 `gorm:"DEFAULT:0"`
|
||||
Email string `gorm:"type:varchar(20);unique_index;"`
|
||||
CreatedAt *time.Time
|
||||
UpdateTAt *time.Time
|
||||
Id int32 `gorm:"AUTO_INCREMENT"`
|
||||
Name string `json:"username"`
|
||||
Pwd string `json:"password"`
|
||||
Phone int64 `gorm:"DEFAULT:0"`
|
||||
Email string `gorm:"type:varchar(20);unique_index;"`
|
||||
CreatedAt *time.Time
|
||||
UpdateTAt *time.Time
|
||||
}
|
||||
|
||||
// LoginReq请求参数
|
||||
|
@ -49,7 +43,7 @@ type LoginReq struct {
|
|||
}
|
||||
|
||||
// 登陆结果
|
||||
type LoginResult struct {
|
||||
type LoginResultTemplate struct {
|
||||
Token string `json:"token"`
|
||||
// 用户模型
|
||||
Name string `json:"name"`
|
||||
|
@ -57,15 +51,21 @@ type LoginResult struct {
|
|||
}
|
||||
|
||||
var (
|
||||
TokenExpired error = errors.New("Token is expired")
|
||||
TokenNotValidYet error = errors.New("Token not active yet")
|
||||
TokenMalformed error = errors.New("That's not even a token")
|
||||
TokenInvalid error = errors.New("Couldn't handle this token:")
|
||||
SignKey string = "bgbiao.top" // 签名信息应该设置成动态从库中获取
|
||||
TokenExpired error = errors.New("Token is expired")
|
||||
TokenNotValidYet error = errors.New("Token not active yet")
|
||||
TokenMalformed error = errors.New("That's not even a token")
|
||||
TokenInvalid error = errors.New("Couldn't handle this token:")
|
||||
|
||||
loginResult LoginResult
|
||||
LoginResult LoginResultTemplate
|
||||
)
|
||||
|
||||
// 初始化jwt对象
|
||||
func NewJWT() *JWT {
|
||||
return &JWT{
|
||||
[]byte("www.openGW.cn"),
|
||||
}
|
||||
}
|
||||
|
||||
// 调用jwt-go库生成token
|
||||
// 指定编码的算法为jwt.SigningMethodHS256
|
||||
func (j *JWT) CreateToken(claims CustomClaims) (string, error) {
|
||||
|
@ -75,7 +75,6 @@ func (j *JWT) CreateToken(claims CustomClaims) (string, error) {
|
|||
return token.SignedString(j.SigningKey)
|
||||
}
|
||||
|
||||
|
||||
// token解码
|
||||
func (j *JWT) ParserToken(tokenString string) (*CustomClaims, error) {
|
||||
// https://gowalker.org/github.com/dgrijalva/jwt-go#ParseWithClaims
|
||||
|
@ -122,9 +121,9 @@ func JWTAuth() gin.HandlerFunc {
|
|||
token := c.Request.Header.Get("token")
|
||||
if token == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Code" : "-1",
|
||||
"Message" : "请求未携带token,无权限访问",
|
||||
"Data" : "",
|
||||
"Code": "-1",
|
||||
"Message": "请求未携带token,无权限访问",
|
||||
"Data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
|
@ -141,18 +140,18 @@ func JWTAuth() gin.HandlerFunc {
|
|||
// token过期
|
||||
if err == TokenExpired {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Code" : "-1",
|
||||
"Message" : "token授权已过期,请重新申请授权",
|
||||
"Data" : "",
|
||||
"Code": "-1",
|
||||
"Message": "token授权已过期,请重新申请授权",
|
||||
"Data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
// 其他错误
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Code" : "-1",
|
||||
"Message" : err.Error(),
|
||||
"Data" : "",
|
||||
"Code": "-1",
|
||||
"Message": err.Error(),
|
||||
"Data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
|
@ -169,11 +168,6 @@ func LoginCheck(login LoginReq) (bool, User, error) {
|
|||
userData := User{}
|
||||
userExist := false
|
||||
|
||||
//var user = User{
|
||||
// Name:"admin",
|
||||
// Pwd:"admin",
|
||||
//}
|
||||
|
||||
if login.Name == "admin" && login.Pwd == "admin" {
|
||||
userExist = true
|
||||
userData.Name = "admin"
|
||||
|
@ -188,7 +182,7 @@ func LoginCheck(login LoginReq) (bool, User, error) {
|
|||
|
||||
// token生成器
|
||||
// md 为上面定义好的middleware中间件
|
||||
func generateToken(c *gin.Context, user User) {
|
||||
func GenerateToken(c *gin.Context, user User) {
|
||||
// 构造SignKey: 签名和解签名需要使用一个值
|
||||
j := NewJWT()
|
||||
|
||||
|
@ -197,10 +191,9 @@ func generateToken(c *gin.Context, user User) {
|
|||
user.Name,
|
||||
user.Email,
|
||||
jwt.StandardClaims{
|
||||
//NotBefore: int64(time.Now().Unix() - 1000), // 签名生效时间
|
||||
NotBefore: int64(time.Now().Unix()), // 签名生效时间
|
||||
ExpiresAt: int64(time.Now().Unix() + 3600), // 签名过期时间
|
||||
Issuer: "bgbiao.top", // 签名颁发者
|
||||
NotBefore: time.Now().Unix(), // 签名生效时间
|
||||
ExpiresAt: time.Now().Unix() + 3600, // 签名过期时间
|
||||
Issuer: "www.openGW.cn", // 签名颁发者
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -209,25 +202,25 @@ func generateToken(c *gin.Context, user User) {
|
|||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Code" : "-1",
|
||||
"Message" : err.Error(),
|
||||
"Data" : "",
|
||||
"Code": "1",
|
||||
"Message": err.Error(),
|
||||
"Data": "",
|
||||
})
|
||||
}
|
||||
|
||||
log.Println(token)
|
||||
setting.Logger.Infof("jwtToken %v", token)
|
||||
// 封装一个响应数据,返回用户名和token
|
||||
data := LoginResult{
|
||||
data := LoginResultTemplate{
|
||||
Name: user.Name,
|
||||
Token: token,
|
||||
}
|
||||
|
||||
loginResult = data
|
||||
LoginResult = data
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Data" : data,
|
||||
"Message" : "login sucess",
|
||||
"Code" : "0",
|
||||
"Code": "0",
|
||||
"Message": "login sucess",
|
||||
"Data": data,
|
||||
})
|
||||
return
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package httpServer
|
||||
package model
|
||||
|
||||
type Response struct {
|
||||
Code string `json:"Code"`
|
|
@ -0,0 +1,259 @@
|
|||
package httpServer
|
||||
|
||||
import (
|
||||
"goAdapter/httpServer/contorl"
|
||||
"goAdapter/httpServer/middleware"
|
||||
"goAdapter/setting"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RouterWeb() {
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := gin.Default()
|
||||
//router := gin.New()
|
||||
|
||||
exeCurDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
router.Static("/static", exeCurDir+"/webroot/static")
|
||||
router.Static("/plugin", exeCurDir+"/plugin/")
|
||||
router.Static("/layui", exeCurDir+"/webroot/layui")
|
||||
router.Static("/serialHelper", exeCurDir+"/webroot/serialHelper")
|
||||
|
||||
router.StaticFile("/", exeCurDir+"/webroot/index.html")
|
||||
router.StaticFile("/favicon.ico", exeCurDir+"/webroot/favicon.ico")
|
||||
router.StaticFile("/serverConfig.json", exeCurDir+"/webroot/serverConfig.json")
|
||||
|
||||
loginRouter := router.Group("/api/v1/system/")
|
||||
{
|
||||
loginRouter.POST("/login", contorl.ApiLogin)
|
||||
}
|
||||
|
||||
router.Use(middleware.JWTAuth())
|
||||
{
|
||||
systemRouter := router.Group("/api/v1/system")
|
||||
{
|
||||
systemRouter.POST("/reboot", contorl.ApiSystemReboot)
|
||||
|
||||
systemRouter.GET("/status", contorl.ApiGetSystemStatus)
|
||||
|
||||
systemRouter.GET("/backup", contorl.ApiBackupFiles)
|
||||
|
||||
systemRouter.POST("/recover", contorl.ApiRecoverFiles)
|
||||
|
||||
systemRouter.POST("/update", contorl.ApiSystemUpdate)
|
||||
|
||||
systemRouter.GET("/loginParam", contorl.ApiSystemLoginParam)
|
||||
|
||||
systemRouter.GET("/MemUseList", contorl.ApiSystemMemoryUseList)
|
||||
|
||||
systemRouter.GET("/DiskUseList", contorl.ApiSystemDiskUseList)
|
||||
|
||||
systemRouter.GET("/DeviceOnlineList", contorl.ApiSystemDeviceOnlineList)
|
||||
|
||||
systemRouter.GET("/DevicePacketLossList", contorl.ApiSystemDevicePacketLossList)
|
||||
|
||||
systemRouter.POST("/systemRTC", contorl.ApiSystemSetSystemRTC)
|
||||
}
|
||||
|
||||
logRouter := router.Group("/api/v1/log")
|
||||
{
|
||||
logRouter.GET("/param", contorl.ApiGetLogParam)
|
||||
|
||||
logRouter.POST("/param", contorl.ApiSetLogParam)
|
||||
|
||||
logRouter.GET("/filesInfo", contorl.ApiGetLogFilesInfo)
|
||||
|
||||
logRouter.DELETE("/files", contorl.ApiDeleteLogFile)
|
||||
|
||||
logRouter.GET("/file", contorl.ApiGetLogFile)
|
||||
}
|
||||
|
||||
ntpRouter := router.Group("/api/v1/system/ntp")
|
||||
{
|
||||
ntpRouter.POST("/hostAddr", contorl.ApiSystemSetNTPHost)
|
||||
|
||||
ntpRouter.GET("/hostAddr", contorl.ApiSystemGetNTPHost)
|
||||
}
|
||||
|
||||
networkRouter := router.Group("/api/v1/network")
|
||||
{
|
||||
networkRouter.POST("/param", contorl.ApiAddNetwork)
|
||||
|
||||
networkRouter.PUT("/param", contorl.ApiModifyNetwork)
|
||||
|
||||
networkRouter.DELETE("/param", contorl.ApiDeleteNetwork)
|
||||
|
||||
networkRouter.GET("/param", contorl.ApiGetNetwork)
|
||||
|
||||
networkRouter.GET("/linkstate", contorl.ApiGetNetworkLinkState)
|
||||
|
||||
}
|
||||
|
||||
serialRouter := router.Group("/api/v1/serial")
|
||||
{
|
||||
|
||||
serialRouter.GET("/param", contorl.ApiGetSerial)
|
||||
}
|
||||
|
||||
deviceRouter := router.Group("/api/v1/device")
|
||||
{
|
||||
//增加采集接口
|
||||
deviceRouter.POST("/interface", contorl.ApiAddInterface)
|
||||
|
||||
//修改采集接口
|
||||
deviceRouter.PUT("/interface", contorl.ApiModifyInterface)
|
||||
|
||||
//删除采集接口
|
||||
deviceRouter.DELETE("/interface", contorl.ApiDeleteInterface)
|
||||
|
||||
//获取接口信息
|
||||
deviceRouter.GET("/interface", contorl.ApiGetInterfaceInfo)
|
||||
|
||||
//获取所有接口信息
|
||||
deviceRouter.GET("/allInterface", contorl.ApiGetAllInterfaceInfo)
|
||||
|
||||
//增加节点
|
||||
deviceRouter.POST("/node", contorl.ApiAddNode)
|
||||
|
||||
//修改单个节点
|
||||
deviceRouter.PUT("/node", contorl.ApiModifyNode)
|
||||
|
||||
//修改多个节点
|
||||
deviceRouter.PUT("/nodes", contorl.ApiModifyNodes)
|
||||
|
||||
//查看节点
|
||||
deviceRouter.GET("/node", contorl.ApiGetNode)
|
||||
|
||||
//查看节点变量
|
||||
deviceRouter.GET("/nodeVariable", contorl.ApiGetNodeVariableFromCache)
|
||||
|
||||
//查看节点历史变量
|
||||
deviceRouter.GET("/nodeHistoryVariable", contorl.ApiGetNodeHistoryVariableFromCache)
|
||||
|
||||
//查看节点变量实时值
|
||||
deviceRouter.GET("/nodeRealVariable", contorl.ApiGetNodeReadVariable)
|
||||
|
||||
//删除节点
|
||||
deviceRouter.DELETE("/node", contorl.ApiDeleteNode)
|
||||
|
||||
//增加设备模板
|
||||
//deviceRouter.POST("/template", ApiAddTemplate)
|
||||
|
||||
//获取设备模板
|
||||
//deviceRouter.GET("/template", ApiGetTemplate)
|
||||
|
||||
//增加设备物模型
|
||||
deviceRouter.POST("/tsl", contorl.ApiAddDeviceTSL)
|
||||
|
||||
//删除设备物模型
|
||||
deviceRouter.DELETE("/tsl", contorl.ApiDeleteDeviceTSL)
|
||||
|
||||
//修改设备物模型
|
||||
deviceRouter.PUT("/tsl", contorl.ApiModifyDeviceTSL)
|
||||
|
||||
//查看设备物模型
|
||||
deviceRouter.GET("/tsl", contorl.ApiGetDeviceTSL)
|
||||
|
||||
//查看设备物模型内容
|
||||
deviceRouter.GET("/tsl/contents", contorl.ApiGetDeviceTSLContents)
|
||||
|
||||
//批量导入设备物模型内容
|
||||
deviceRouter.POST("/tsl/contents/csv", contorl.ApiImportDeviceTSLContents)
|
||||
|
||||
//批量导出设备物模型内容
|
||||
deviceRouter.GET("/tsl/contents/csv", contorl.ApiExportDeviceTSLContents)
|
||||
|
||||
//导出设备物模型内容模板
|
||||
deviceRouter.GET("/tsl/contents/template", contorl.ApiExportDeviceTSLContentsTemplate)
|
||||
|
||||
//导入设备物模型插件
|
||||
deviceRouter.POST("/tsl/plugin", contorl.ApiImportDeviceTSLPlugin)
|
||||
|
||||
//导出设备物模型插件
|
||||
deviceRouter.GET("/tsl/plugin", contorl.ApiExportDeviceTSLPlugin)
|
||||
|
||||
//增加设备物模型属性
|
||||
deviceRouter.POST("/tsl/property", contorl.ApiAddDeviceTSLProperty)
|
||||
|
||||
//修改设备物模型属性
|
||||
deviceRouter.PUT("/tsl/property", contorl.ApiModifyDeviceTSLProperty)
|
||||
|
||||
//删除设备物模型属性
|
||||
deviceRouter.DELETE("/tsl/properties", contorl.ApiDeleteDeviceTSLProperties)
|
||||
|
||||
//查看设备物模型属性
|
||||
deviceRouter.GET("/tsl/properties", contorl.ApiGetDeviceTSLProperties)
|
||||
|
||||
//增加设备物模型服务
|
||||
deviceRouter.POST("/tsl/service", contorl.ApiAddDeviceTSLService)
|
||||
|
||||
//修改设备物模型服务
|
||||
deviceRouter.PUT("/tsl/service", contorl.ApiModifyDeviceTSLService)
|
||||
|
||||
//删除设备物模型服务
|
||||
deviceRouter.DELETE("/tsl/services", contorl.ApiDeleteDeviceTSLServices)
|
||||
|
||||
//获取通信接口
|
||||
deviceRouter.GET("/commInterface", contorl.ApiGetCommInterface)
|
||||
|
||||
//增加通信接口
|
||||
deviceRouter.POST("/commInterface", contorl.ApiAddCommInterface)
|
||||
|
||||
//修改通信接口
|
||||
deviceRouter.PUT("/commInterface", contorl.ApiModifyCommInterface)
|
||||
|
||||
//删除通信接口
|
||||
deviceRouter.DELETE("/commInterface", contorl.ApiDeleteCommInterface)
|
||||
|
||||
//增加串口通信接口
|
||||
deviceRouter.POST("/commSerialInterface", contorl.ApiAddCommSerialInterface)
|
||||
|
||||
//修改串口通信接口
|
||||
deviceRouter.PUT("/commSerialInterface", contorl.ApiModifyCommSerialInterface)
|
||||
|
||||
//删除串口通信接口
|
||||
deviceRouter.DELETE("/commSerialInterface", contorl.ApiDeleteCommSerialInterface)
|
||||
|
||||
//调用设备服务
|
||||
deviceRouter.POST("/service", contorl.ApiInvokeService)
|
||||
|
||||
//向采集接口发送透传数据
|
||||
deviceRouter.POST("/interface/directData", contorl.ApiSendDirectDataToCollInterface)
|
||||
}
|
||||
|
||||
toolRouter := router.Group("/api/v1/tool")
|
||||
{
|
||||
//获取通信报文
|
||||
toolRouter.POST("/commMessage", contorl.ApiGetCommMessage)
|
||||
}
|
||||
|
||||
pluginRouter := router.Group("/api/v1/update")
|
||||
{
|
||||
pluginRouter.POST("/plugin", contorl.ApiUpdatePlugin)
|
||||
}
|
||||
|
||||
reportRouter := router.Group("/api/v1/report")
|
||||
{
|
||||
reportRouter.POST("/param", contorl.ApiSetReportGWParam)
|
||||
|
||||
reportRouter.GET("/param", contorl.ApiGetReportGWParam)
|
||||
|
||||
reportRouter.DELETE("/param", contorl.ApiDeleteReportGWParam)
|
||||
|
||||
reportRouter.POST("/node/param", contorl.ApiSetReportNodeWParam)
|
||||
|
||||
reportRouter.POST("/nodes/param", contorl.ApiBatchAddReportNodeParam)
|
||||
|
||||
reportRouter.GET("/node/param", contorl.ApiGetReportNodeWParam)
|
||||
|
||||
reportRouter.DELETE("/node/param", contorl.ApiDeleteReportNodeWParam)
|
||||
}
|
||||
}
|
||||
|
||||
if err := router.Run(":8080"); err != nil {
|
||||
setting.Logger.Errorf("gin run err,%v", err)
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package httpServer
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func routerCommon() http.Handler {
|
||||
router := gin.Default()
|
||||
//router := gin.New()
|
||||
|
||||
systemRouter := router.Group("/api/v1/system")
|
||||
{
|
||||
systemRouter.POST("/reboot", apiSystemReboot)
|
||||
|
||||
systemRouter.GET("/status", apiGetSystemStatus)
|
||||
|
||||
systemRouter.GET("/loginParam", apiSystemLoginParam)
|
||||
}
|
||||
|
||||
//networkRouter := router.Group("/api/v1/network")
|
||||
//{
|
||||
// networkRouter.POST("/param", apiSetNetwork)
|
||||
//
|
||||
// networkRouter.GET("/param", apiGetNetwork)
|
||||
//
|
||||
// networkRouter.GET("/linkstate", apiGetNetworkLinkState)
|
||||
//}
|
||||
|
||||
serialRouter := router.Group("/api/v1/serial/param")
|
||||
{
|
||||
serialRouter.GET("", apiGetSerial)
|
||||
}
|
||||
|
||||
deviceRouter := router.Group("/api/v1/device")
|
||||
{
|
||||
//增加接口
|
||||
deviceRouter.POST("/interface", apiAddInterface)
|
||||
|
||||
//修改接口
|
||||
deviceRouter.PUT("/interface", apiModifyInterface)
|
||||
|
||||
//获取接口信息
|
||||
deviceRouter.GET("/interface", apiGetInterfaceInfo)
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
package httpServer
|
||||
|
||||
import (
|
||||
"goAdapter/setting"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RouterWeb() {
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := gin.Default()
|
||||
//router := gin.New()
|
||||
|
||||
exeCurDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
router.Static("/static", exeCurDir+"/webroot/static")
|
||||
router.Static("/plugin", exeCurDir+"/plugin/")
|
||||
router.Static("/layui", exeCurDir+"/webroot/layui")
|
||||
router.Static("/serialHelper", exeCurDir+"/webroot/serialHelper")
|
||||
|
||||
router.StaticFile("/", exeCurDir+"/webroot/index.html")
|
||||
router.StaticFile("/favicon.ico", exeCurDir+"/webroot/favicon.ico")
|
||||
router.StaticFile("/serverConfig.json", exeCurDir+"/webroot/serverConfig.json")
|
||||
|
||||
loginRouter := router.Group("/api/v1/system/")
|
||||
{
|
||||
loginRouter.POST("/login", apiLogin)
|
||||
}
|
||||
|
||||
router.Use(JWTAuth())
|
||||
{
|
||||
systemRouter := router.Group("/api/v1/system")
|
||||
{
|
||||
systemRouter.POST("/reboot", apiSystemReboot)
|
||||
|
||||
systemRouter.GET("/status", apiGetSystemStatus)
|
||||
|
||||
systemRouter.GET("/backup", apiBackupFiles)
|
||||
|
||||
systemRouter.POST("/recover", apiRecoverFiles)
|
||||
|
||||
systemRouter.POST("/update", apiSystemUpdate)
|
||||
|
||||
systemRouter.GET("/loginParam", apiSystemLoginParam)
|
||||
|
||||
systemRouter.GET("/MemUseList", apiSystemMemoryUseList)
|
||||
|
||||
systemRouter.GET("/DiskUseList", apiSystemDiskUseList)
|
||||
|
||||
systemRouter.GET("/DeviceOnlineList", apiSystemDeviceOnlineList)
|
||||
|
||||
systemRouter.GET("/DevicePacketLossList", apiSystemDevicePacketLossList)
|
||||
|
||||
systemRouter.POST("/systemRTC", apiSystemSetSystemRTC)
|
||||
}
|
||||
|
||||
logRouter := router.Group("/api/v1/log")
|
||||
{
|
||||
logRouter.GET("/param", apiGetLogParam)
|
||||
|
||||
logRouter.POST("/param", apiSetLogParam)
|
||||
|
||||
logRouter.GET("/filesInfo", apiGetLogFilesInfo)
|
||||
|
||||
logRouter.DELETE("/files", apiDeleteLogFile)
|
||||
|
||||
logRouter.GET("/file", apiGetLogFile)
|
||||
}
|
||||
|
||||
ntpRouter := router.Group("/api/v1/system/ntp")
|
||||
{
|
||||
ntpRouter.POST("/hostAddr", apiSystemSetNTPHost)
|
||||
|
||||
ntpRouter.GET("/hostAddr", apiSystemGetNTPHost)
|
||||
}
|
||||
|
||||
networkRouter := router.Group("/api/v1/network")
|
||||
{
|
||||
networkRouter.POST("/param", apiAddNetwork)
|
||||
|
||||
networkRouter.PUT("/param", apiModifyNetwork)
|
||||
|
||||
networkRouter.DELETE("/param", apiDeleteNetwork)
|
||||
|
||||
networkRouter.GET("/param", apiGetNetwork)
|
||||
|
||||
networkRouter.GET("/linkstate", apiGetNetworkLinkState)
|
||||
|
||||
}
|
||||
|
||||
serialRouter := router.Group("/api/v1/serial")
|
||||
{
|
||||
|
||||
serialRouter.GET("/param", apiGetSerial)
|
||||
}
|
||||
|
||||
deviceRouter := router.Group("/api/v1/device")
|
||||
{
|
||||
//增加采集接口
|
||||
deviceRouter.POST("/interface", apiAddInterface)
|
||||
|
||||
//修改采集接口
|
||||
deviceRouter.PUT("/interface", apiModifyInterface)
|
||||
|
||||
//删除采集接口
|
||||
deviceRouter.DELETE("/interface", apiDeleteInterface)
|
||||
|
||||
//获取接口信息
|
||||
deviceRouter.GET("/interface", apiGetInterfaceInfo)
|
||||
|
||||
//获取所有接口信息
|
||||
deviceRouter.GET("/allInterface", apiGetAllInterfaceInfo)
|
||||
|
||||
//增加节点
|
||||
deviceRouter.POST("/node", apiAddNode)
|
||||
|
||||
//修改单个节点
|
||||
deviceRouter.PUT("/node", apiModifyNode)
|
||||
|
||||
//修改多个节点
|
||||
deviceRouter.PUT("/nodes", apiModifyNodes)
|
||||
|
||||
//查看节点
|
||||
deviceRouter.GET("/node", apiGetNode)
|
||||
|
||||
//查看节点变量
|
||||
deviceRouter.GET("/nodeVariable", apiGetNodeVariableFromCache)
|
||||
|
||||
//查看节点历史变量
|
||||
deviceRouter.GET("/nodeHistoryVariable", apiGetNodeHistoryVariableFromCache)
|
||||
|
||||
//查看节点变量实时值
|
||||
deviceRouter.GET("/nodeRealVariable", apiGetNodeReadVariable)
|
||||
|
||||
//删除节点
|
||||
deviceRouter.DELETE("/node", apiDeleteNode)
|
||||
|
||||
//增加设备模板
|
||||
//deviceRouter.POST("/template", apiAddTemplate)
|
||||
|
||||
//获取设备模板
|
||||
//deviceRouter.GET("/template", apiGetTemplate)
|
||||
|
||||
//增加设备物模型
|
||||
deviceRouter.POST("/tsl", apiAddDeviceTSL)
|
||||
|
||||
//删除设备物模型
|
||||
deviceRouter.DELETE("/tsl", apiDeleteDeviceTSL)
|
||||
|
||||
//修改设备物模型
|
||||
deviceRouter.PUT("/tsl", apiModifyDeviceTSL)
|
||||
|
||||
//查看设备物模型
|
||||
deviceRouter.GET("/tsl", apiGetDeviceTSL)
|
||||
|
||||
//查看设备物模型内容
|
||||
deviceRouter.GET("/tsl/contents", apiGetDeviceTSLContents)
|
||||
|
||||
//批量导入设备物模型内容
|
||||
deviceRouter.POST("/tsl/contents/csv", apiImportDeviceTSLContents)
|
||||
|
||||
//批量导出设备物模型内容
|
||||
deviceRouter.GET("/tsl/contents/csv", apiExportDeviceTSLContents)
|
||||
|
||||
//导出设备物模型内容模板
|
||||
deviceRouter.GET("/tsl/contents/template", apiExportDeviceTSLContentsTemplate)
|
||||
|
||||
//导入设备物模型插件
|
||||
deviceRouter.POST("/tsl/plugin", apiImportDeviceTSLPlugin)
|
||||
|
||||
//导出设备物模型插件
|
||||
deviceRouter.GET("/tsl/plugin", apiExportDeviceTSLPlugin)
|
||||
|
||||
//增加设备物模型属性
|
||||
deviceRouter.POST("/tsl/property", apiAddDeviceTSLProperty)
|
||||
|
||||
//修改设备物模型属性
|
||||
deviceRouter.PUT("/tsl/property", apiModifyDeviceTSLProperty)
|
||||
|
||||
//删除设备物模型属性
|
||||
deviceRouter.DELETE("/tsl/properties", apiDeleteDeviceTSLProperties)
|
||||
|
||||
//查看设备物模型属性
|
||||
deviceRouter.GET("/tsl/properties", apiGetDeviceTSLProperties)
|
||||
|
||||
//增加设备物模型服务
|
||||
deviceRouter.POST("/tsl/service", apiAddDeviceTSLService)
|
||||
|
||||
//修改设备物模型服务
|
||||
deviceRouter.PUT("/tsl/service", apiModifyDeviceTSLService)
|
||||
|
||||
//删除设备物模型服务
|
||||
deviceRouter.DELETE("/tsl/services", apiDeleteDeviceTSLServices)
|
||||
|
||||
//获取通信接口
|
||||
deviceRouter.GET("/commInterface", apiGetCommInterface)
|
||||
|
||||
//增加通信接口
|
||||
deviceRouter.POST("/commInterface", apiAddCommInterface)
|
||||
|
||||
//修改通信接口
|
||||
deviceRouter.PUT("/commInterface", apiModifyCommInterface)
|
||||
|
||||
//删除通信接口
|
||||
deviceRouter.DELETE("/commInterface", apiDeleteCommInterface)
|
||||
|
||||
//增加串口通信接口
|
||||
deviceRouter.POST("/commSerialInterface", apiAddCommSerialInterface)
|
||||
|
||||
//修改串口通信接口
|
||||
deviceRouter.PUT("/commSerialInterface", apiModifyCommSerialInterface)
|
||||
|
||||
//删除串口通信接口
|
||||
deviceRouter.DELETE("/commSerialInterface", apiDeleteCommSerialInterface)
|
||||
|
||||
//调用设备服务
|
||||
deviceRouter.POST("/service", apiInvokeService)
|
||||
|
||||
//向采集接口发送透传数据
|
||||
deviceRouter.POST("/interface/directData", apiSendDirectDataToCollInterface)
|
||||
}
|
||||
|
||||
toolRouter := router.Group("/api/v1/tool")
|
||||
{
|
||||
//获取通信报文
|
||||
toolRouter.POST("/commMessage", apiGetCommMessage)
|
||||
}
|
||||
|
||||
pluginRouter := router.Group("/api/v1/update")
|
||||
{
|
||||
pluginRouter.POST("/plugin", apiUpdatePlugin)
|
||||
}
|
||||
|
||||
reportRouter := router.Group("/api/v1/report")
|
||||
{
|
||||
reportRouter.POST("/param", apiSetReportGWParam)
|
||||
|
||||
reportRouter.GET("/param", apiGetReportGWParam)
|
||||
|
||||
reportRouter.DELETE("/param", apiDeleteReportGWParam)
|
||||
|
||||
reportRouter.POST("/node/param", apiSetReportNodeWParam)
|
||||
|
||||
reportRouter.POST("/nodes/param", apiBatchAddReportNodeParam)
|
||||
|
||||
reportRouter.GET("/node/param", apiGetReportNodeWParam)
|
||||
|
||||
reportRouter.DELETE("/node/param", apiDeleteReportNodeWParam)
|
||||
}
|
||||
}
|
||||
|
||||
if err := router.Run(":8080"); err != nil {
|
||||
setting.Logger.Errorf("gin run err,%v", err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue