auth.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. type GuoNengController struct{}
  12. func (gc *GuoNengController) GetToken(c *gin.Context) {
  13. var req gnRequest.GetTokenReq
  14. if e := c.Bind(&req); e != nil {
  15. err, ok := e.(validator.ValidationErrors)
  16. if !ok {
  17. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  18. return
  19. }
  20. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  21. return
  22. }
  23. if req.Code == "" {
  24. resp.FailMsg("请传入code码", "请输入指标code码", c)
  25. return
  26. }
  27. result, err, errMsg := gn.LoginEta(req.Code)
  28. if err != nil {
  29. fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg)
  30. resp.FailData(errMsg, err.Error(), c)
  31. return
  32. }
  33. resp.OkData("获取成功", result, c)
  34. }
  35. func (gc *GuoNengController) GetUserInfo(c *gin.Context) {
  36. var req gnRequest.GetUserInfoReq
  37. if e := c.Bind(&req); e != nil {
  38. err, ok := e.(validator.ValidationErrors)
  39. if !ok {
  40. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  41. return
  42. }
  43. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  44. return
  45. }
  46. if req.Token == "" {
  47. resp.FailMsg("请传入token", "请传入token", c)
  48. return
  49. }
  50. result, err, errMsg := gn.GetUserInfoByToken(req.Token)
  51. if err != nil {
  52. fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg)
  53. resp.FailData(errMsg, err.Error(), c)
  54. return
  55. }
  56. resp.OkData("获取成功", result, c)
  57. }