auth.go 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package param
  2. import (
  3. "context"
  4. "encoding/json"
  5. )
  6. //GetUserID 临时的,account 新版本为accountid
  7. func GetUserID(c context.Context) int64 {
  8. userID := c.Value("user_id")
  9. if _, ok := userID.(int64); ok {
  10. return userID.(int64)
  11. }
  12. return 0
  13. }
  14. func GetAccountID(c context.Context) int64 {
  15. accountID := c.Value("account_id")
  16. if _, ok := accountID.(int64); ok {
  17. return accountID.(int64)
  18. }
  19. return 0
  20. }
  21. //GetMemberID 临时的,account 新版本为userid
  22. func GetMemberID(c context.Context) int64 {
  23. userID := c.Value("mem_id")
  24. if _, ok := userID.(int64); ok {
  25. return userID.(int64)
  26. }
  27. return 0
  28. }
  29. func GetAuthToken(c context.Context) string {
  30. token := c.Value("token")
  31. if _, ok := token.(string); ok {
  32. return token.(string)
  33. }
  34. return ""
  35. }
  36. func GetJwtClaims(c context.Context) json.RawMessage {
  37. claim := c.Value("claim")
  38. if _, ok := claim.(json.RawMessage); ok {
  39. return claim.(json.RawMessage)
  40. }
  41. return []byte{}
  42. }