user.go 648 B

12345678910111213141516171819202122232425262728293031323334
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. const (
  7. _sessUnKey = "username"
  8. )
  9. // @params EmptyReq
  10. // @router get /ep/admin/saga/v1/user
  11. // @response User
  12. func queryUserInfo(ctx *bm.Context) {
  13. var (
  14. userName string
  15. err error
  16. )
  17. if userName, err = getUsername(ctx); err != nil {
  18. return
  19. }
  20. ctx.JSON(srv.UserInfo(userName), nil)
  21. }
  22. func getUsername(c *bm.Context) (string, error) {
  23. if user, err := c.Request.Cookie(_sessUnKey); err == nil {
  24. return user.Value, nil
  25. }
  26. if value, exist := c.Get(_sessUnKey); exist {
  27. return value.(string), nil
  28. }
  29. return "", ecode.AccessKeyErr
  30. }