1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package isapi
- import (
- "errors"
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "io/ioutil"
- "lcfns/gatewayServer"
- "lcfns/isapi"
- "strings"
- )
- type SystemApi struct {
- }
- func (i SystemApi) GetInfo(c *gin.Context) {
- host, err := GetHost(c)
- if err != nil {
- logrus.Errorf("获取host失败:%e\n", err)
- return
- }
- //data, err :=
- isapi.TouChuan(host, isapi.GetDeviceInfo, nil, c)
- //if err != nil {
- // response.FailWithMessage(err.Error(), c)
- // return
- //}
- //response.OkWithData(data, c)
- }
- func (i SystemApi) GetCap(c *gin.Context) {
- host, err := GetHost(c)
- if err != nil {
- logrus.Errorf("获取host失败:%e\n", err)
- return
- }
- isapi.TouChuan(host, isapi.GetSystemCap, nil, c)
- }
- func (i SystemApi) PutEmail(c *gin.Context) {
- defer c.Request.Body.Close()
- data, err := ioutil.ReadAll(c.Request.Body)
- if err != nil {
- logrus.Errorf("读取数据失败:%e\n", err)
- }
- host, err := GetHost(c)
- if err != nil {
- logrus.Errorf("获取host失败:%e\n", err)
- return
- }
- isapi.TouChuan(host, isapi.PutEmail, data, c)
- }
- func GetHost(c *gin.Context) (string, error) {
- //devId := c.Query("devId")
- isn := c.GetHeader("isn")
- if isn == "" {
- return "", errors.New("网关isn为空")
- }
- conn, ok := gatewayServer.ConnMap[isn]
- if !ok {
- return "", errors.New("获取设备Id对应连接失败")
- }
- return strings.Split(conn.RemoteAddr().String(), ":")[0] + ":8848", nil
- }
|