detailLogic.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package user
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "microGame/app/usercenter/cmd/rpc/pb/usercenter"
  7. "microGame/pkg/ctxdata"
  8. "microGame/app/usercenter/cmd/api/internal/svc"
  9. "microGame/app/usercenter/cmd/api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type DetailLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. // NewDetailLogic get user info
  18. func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
  19. return &DetailLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *DetailLogic) Detail(req *types.UserInfoReq) (resp *types.UserInfoResp, err error) {
  26. userId := ctxdata.GetUidFromCtx(l.ctx)
  27. detailResp, err := l.svcCtx.UserRpc.GetUserInfo(l.ctx, &usercenter.UserInfoReq{
  28. UserId: userId,
  29. })
  30. if err != nil {
  31. return nil, err
  32. }
  33. //value := l.ctx.Value("jwtUserId")
  34. //logc.Info(l.ctx, value)
  35. //str := fmt.Sprintf("%s", userId)
  36. msg, _ := json.Marshal(detailResp)
  37. if err := l.svcCtx.KqPusherClient.Push(l.ctx, string(msg)); err != nil {
  38. logx.Errorf("KqPusherClient Push Error , err :%+v\n", err)
  39. }
  40. fmt.Printf("KqPusherClient Push connect req , err :%+v\n", err)
  41. resp = &types.UserInfoResp{
  42. Uid: detailResp.Uid,
  43. Username: detailResp.Username,
  44. }
  45. return
  46. }