123456789101112131415161718 |
- package middleware
- import (
- "github.com/gin-gonic/gin"
- "gogs.tyduyong.com/duyong/dy-pkg/logs"
- )
- // UsernameKey defines the key in gin context which represents the owner of the secret.
- const UsernameKey = "username"
- // Context is a middleware that injects common prefix fields to gin.Context.
- func Context() gin.HandlerFunc {
- return func(c *gin.Context) {
- c.Set(logs.KeyRequestID, c.GetString(XRequestIDKey))
- c.Set(logs.KeyUsername, c.GetString(UsernameKey))
- c.Next()
- }
- }
|