auth.go 956 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package gn
  2. import (
  3. "eta_gn/eta_bridge/controller/resp"
  4. "eta_gn/eta_bridge/global"
  5. "eta_gn/eta_bridge/logic/gn"
  6. gnRequest "eta_gn/eta_bridge/models/request/gn"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. "github.com/go-playground/validator/v10"
  10. )
  11. // GuoNengController 国能
  12. type GuoNengController struct{}
  13. func (gc *GuoNengController) GetToken(c *gin.Context) {
  14. var req gnRequest.GetTokenReq
  15. if e := c.Bind(&req); e != nil {
  16. err, ok := e.(validator.ValidationErrors)
  17. if !ok {
  18. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  19. return
  20. }
  21. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  22. return
  23. }
  24. if req.Code == "" {
  25. resp.FailMsg("请传入code码", "请输入指标code码", c)
  26. return
  27. }
  28. result, err, errMsg := gn.LoginEta(req.Code)
  29. if err != nil {
  30. fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg)
  31. resp.FailData(errMsg, err.Error(), c)
  32. return
  33. }
  34. resp.OkData("获取成功", result, c)
  35. }