package gn import ( "eta_gn/eta_bridge/controller/resp" "eta_gn/eta_bridge/global" "eta_gn/eta_bridge/logic/gn" gnRequest "eta_gn/eta_bridge/models/request/gn" "fmt" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" ) type GuoNengController struct{} func (gc *GuoNengController) GetToken(c *gin.Context) { var req gnRequest.GetTokenReq if e := c.Bind(&req); e != nil { err, ok := e.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+e.Error(), c) return } resp.FailData("参数解析失败", err.Translate(global.Trans), c) return } if req.Code == "" { resp.FailMsg("请传入code码", "请输入指标code码", c) return } result, err, errMsg := gn.LoginEta(req.Code) if err != nil { fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg) resp.FailData(errMsg, err.Error(), c) return } resp.OkData("获取成功", result, c) } func (gc *GuoNengController) GetUserInfo(c *gin.Context) { var req gnRequest.GetUserInfoReq if e := c.Bind(&req); e != nil { err, ok := e.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+e.Error(), c) return } resp.FailData("参数解析失败", err.Translate(global.Trans), c) return } if req.Token == "" { resp.FailMsg("请传入token", "请传入token", c) return } result, err, errMsg := gn.GetUserInfoByToken(req.Token) if err != nil { fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg) resp.FailData(errMsg, err.Error(), c) return } resp.OkData("获取成功", result, c) }