123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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
- }
|