context.go 646 B

123456789101112131415161718192021222324
  1. // Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package middleware
  5. import (
  6. "github.com/gin-gonic/gin"
  7. )
  8. // UsernameKey defines the key in gin context which represents the owner of the secret.
  9. const (
  10. RequestIDKey = "requestID"
  11. UsernameKey = "username"
  12. )
  13. // Context is a jwtauth that injects common prefix fields to gin.Context.
  14. func Context() gin.HandlerFunc {
  15. return func(c *gin.Context) {
  16. c.Set(RequestIDKey, c.GetString(XRequestIDKey))
  17. c.Set(UsernameKey, c.GetString(UsernameKey))
  18. c.Next()
  19. }
  20. }