get_user_info.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. log "github.com/sirupsen/logrus"
  6. "youngee_b_api/consts"
  7. "youngee_b_api/model/http_model"
  8. "youngee_b_api/service"
  9. "youngee_b_api/util"
  10. )
  11. func WrapGetUserInfoHandler(ctx *gin.Context) {
  12. handler := newGetUserInfoHandler(ctx)
  13. userToken := ctx.Request.Header.Get("Authorization")
  14. handler.req.Token = userToken
  15. baseRun(handler)
  16. }
  17. func newGetUserInfoHandler(ctx *gin.Context) *GetUserInfoHandler {
  18. return &GetUserInfoHandler{
  19. req: http_model.NewGetUserInfoRequest(),
  20. resp: http_model.NewGetUserInfoResponse(),
  21. ctx: ctx,
  22. }
  23. }
  24. type GetUserInfoHandler struct {
  25. req *http_model.GetUserInfoRequest
  26. resp *http_model.CommonResponse
  27. ctx *gin.Context
  28. }
  29. func (h *GetUserInfoHandler) getRequest() interface{} {
  30. return h.req
  31. }
  32. func (h *GetUserInfoHandler) getContext() *gin.Context {
  33. return h.ctx
  34. }
  35. func (h *GetUserInfoHandler) getResponse() interface{} {
  36. return h.resp
  37. }
  38. func (h *GetUserInfoHandler) run() {
  39. userData, err := service.SUserInfo.FindBUserInfoByToken(h.ctx, h.req.Token)
  40. if err != nil {
  41. logrus.Errorf("[CodeLoginHandler] call AuthCode err:%+v\n", err)
  42. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
  43. log.Info("login fail,req:%+v", h.req)
  44. return
  45. }
  46. var data *http_model.GetUserInfoData
  47. data = userData
  48. h.resp.Message = "成功查询用户信息"
  49. h.resp.Data = data
  50. h.resp.Status = 20000
  51. return
  52. }
  53. func (h *GetUserInfoHandler) checkParam() error {
  54. return nil
  55. }