system.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package isapi
  2. import (
  3. "errors"
  4. "github.com/gin-gonic/gin"
  5. "github.com/sirupsen/logrus"
  6. "io/ioutil"
  7. "lcfns/gatewayServer"
  8. "lcfns/isapi"
  9. "strings"
  10. )
  11. type SystemApi struct {
  12. }
  13. func (i SystemApi) GetInfo(c *gin.Context) {
  14. host, err := GetHost(c)
  15. if err != nil {
  16. logrus.Errorf("获取host失败:%e\n", err)
  17. return
  18. }
  19. //data, err :=
  20. isapi.TouChuan(host, isapi.GetDeviceInfo, nil, c)
  21. //if err != nil {
  22. // response.FailWithMessage(err.Error(), c)
  23. // return
  24. //}
  25. //response.OkWithData(data, c)
  26. }
  27. func (i SystemApi) GetCap(c *gin.Context) {
  28. host, err := GetHost(c)
  29. if err != nil {
  30. logrus.Errorf("获取host失败:%e\n", err)
  31. return
  32. }
  33. isapi.TouChuan(host, isapi.GetSystemCap, nil, c)
  34. }
  35. func (i SystemApi) PutEmail(c *gin.Context) {
  36. defer c.Request.Body.Close()
  37. data, err := ioutil.ReadAll(c.Request.Body)
  38. if err != nil {
  39. logrus.Errorf("读取数据失败:%e\n", err)
  40. }
  41. host, err := GetHost(c)
  42. if err != nil {
  43. logrus.Errorf("获取host失败:%e\n", err)
  44. return
  45. }
  46. isapi.TouChuan(host, isapi.PutEmail, data, c)
  47. }
  48. func GetHost(c *gin.Context) (string, error) {
  49. //devId := c.Query("devId")
  50. isn := c.GetHeader("isn")
  51. if isn == "" {
  52. return "", errors.New("网关isn为空")
  53. }
  54. conn, ok := gatewayServer.ConnMap[isn]
  55. if !ok {
  56. return "", errors.New("获取设备Id对应连接失败")
  57. }
  58. return strings.Split(conn.RemoteAddr().String(), ":")[0] + ":8848", nil
  59. }