context_keys.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package middleware
  5. // ContextKey represents a context key.
  6. type ContextKey struct {
  7. name string
  8. }
  9. func (c ContextKey) String() string {
  10. return c.name
  11. }
  12. var (
  13. // UserIDContextKey is the context key used to store the user ID.
  14. UserIDContextKey = &ContextKey{"UserID"}
  15. // UserTimezoneContextKey is the context key used to store the user timezone.
  16. UserTimezoneContextKey = &ContextKey{"UserTimezone"}
  17. // IsAdminUserContextKey is the context key used to store the user role.
  18. IsAdminUserContextKey = &ContextKey{"IsAdminUser"}
  19. // IsAuthenticatedContextKey is the context key used to store the authentication flag.
  20. IsAuthenticatedContextKey = &ContextKey{"IsAuthenticated"}
  21. // UserSessionTokenContextKey is the context key used to store the user session ID.
  22. UserSessionTokenContextKey = &ContextKey{"UserSessionToken"}
  23. // SessionIDContextKey is the context key used to store the session ID.
  24. SessionIDContextKey = &ContextKey{"SessionID"}
  25. // CSRFContextKey is the context key used to store CSRF token.
  26. CSRFContextKey = &ContextKey{"CSRF"}
  27. // OAuth2StateContextKey is the context key used to store OAuth2 state.
  28. OAuth2StateContextKey = &ContextKey{"OAuth2State"}
  29. // FlashMessageContextKey is the context key used to store a flash message.
  30. FlashMessageContextKey = &ContextKey{"FlashMessage"}
  31. // FlashErrorMessageContextKey is the context key used to store a flash error message.
  32. FlashErrorMessageContextKey = &ContextKey{"FlashErrorMessage"}
  33. )