1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package isapi
- import (
- "errors"
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "io/ioutil"
- "lc-fangdaosha/gatewayServer"
- "lc-fangdaosha/isapi"
- "strings"
- )
- type SystemApi struct {
- }
- // GetInfo 获取设备信息
- func (i SystemApi) GetInfo(c *gin.Context) {
- host, err := GetHost(c)
- if err != nil {
- logrus.Errorf("获取设备连接失败:%e\n", err)
- return
- }
- isapi.TouChuan(host, isapi.GetDeviceInfo, nil, c)
- }
- // GetCap 获取设备能力集
- func (i SystemApi) GetCap(c *gin.Context) {
- host, err := GetHost(c)
- if err != nil {
- logrus.Errorf("获取设备连接失败:%e\n", err)
- return
- }
- isapi.TouChuan(host, isapi.GetSystemCap, nil, c)
- }
- // PutEmail 配置邮箱
- func (i SystemApi) PutEmail(c *gin.Context) {
- defer c.Request.Body.Close()
- all, err := ioutil.ReadAll(c.Request.Body)
- if err != nil {
- logrus.Errorf("读取数据失败:%e\n", err)
- }
- host, err := GetHost(c)
- if err != nil {
- logrus.Errorf("获取设备连接失败:%e\n", err)
- return
- }
- isapi.TouChuan(host, isapi.PutEmail, all, c)
- }
- // GetHost 获取设备连接的host
- func GetHost(c *gin.Context) (string, error) {
- 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
- }
|