system.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if devId == "" {
  51. return "", errors.New("设备Id为空")
  52. }
  53. conn, ok := gatewayServer.ConnMap[devId]
  54. if !ok {
  55. return "", errors.New("获取设备Id对应连接失败")
  56. }
  57. return strings.Split(conn.RemoteAddr().String(), ":")[0] + ":8848", nil
  58. }