package xiangyu import ( "eta/eta_bridge/controller/resp" "eta/eta_bridge/global" "eta/eta_bridge/logic/xiangyu" xyReq "eta/eta_bridge/models/request/xiangyu" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" ) // GetToken // @Description: 获取token // @author: Roc // @receiver xc // @datetime 2024-01-23 17:06:34 // @param c *gin.Context func (xc *XiangyuController) GetToken(c *gin.Context) { var req xyReq.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 := xiangyu.LoginEta(req.Code) if err != nil { resp.FailData(errMsg, err.Error(), c) return } resp.OkData("获取成功", result, c) return } // RefreshToken // @Description: 刷新token // @author: Roc // @receiver xc // @datetime 2024-01-23 17:06:25 // @param c *gin.Context func (xc *XiangyuController) RefreshToken(c *gin.Context) { var req xyReq.RefreshTokenReq 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.RefreshToken == "" { resp.FailMsg("请传入refresh_token", "请传入refresh_token", c) return } err := xiangyu.RefreshToken(req.RefreshToken) if err != nil { resp.FailData("参数解析失败", err.Error(), c) return } resp.Ok("刷新成功", c) return } // RevokeToken // @Description: 销毁token // @author: Roc // @receiver xc // @datetime 2024-01-23 17:06:12 // @param c *gin.Context func (xc *XiangyuController) RevokeToken(c *gin.Context) { var req xyReq.RevokeTokenReq 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 } err := xiangyu.RevokeToken(req.Token) if err != nil { resp.FailData("参数解析失败", err.Error(), c) return } resp.Ok("销毁成功", c) return }