context.go 448 B

123456789101112131415161718192021222324
  1. package permlib
  2. import "context"
  3. type contextKey string
  4. const ctxKeyUser contextKey = "permlib_user"
  5. type UserInfo struct {
  6. UserId int64
  7. Username string
  8. ProductCode string
  9. MemberType string
  10. Perms []string
  11. }
  12. func GetUser(ctx context.Context) *UserInfo {
  13. v, _ := ctx.Value(ctxKeyUser).(*UserInfo)
  14. return v
  15. }
  16. func withUser(ctx context.Context, u *UserInfo) context.Context {
  17. return context.WithValue(ctx, ctxKeyUser, u)
  18. }