context.go 484 B

123456789101112131415161718
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "gogs.tyduyong.com/duyong/dy-pkg/logs"
  5. )
  6. // UsernameKey defines the key in gin context which represents the owner of the secret.
  7. const UsernameKey = "username"
  8. // Context is a middleware that injects common prefix fields to gin.Context.
  9. func Context() gin.HandlerFunc {
  10. return func(c *gin.Context) {
  11. c.Set(logs.KeyRequestID, c.GetString(XRequestIDKey))
  12. c.Set(logs.KeyUsername, c.GetString(UsernameKey))
  13. c.Next()
  14. }
  15. }