首次提交:初始化项目代码
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"resume-platform/pkg/constant"
|
||||
"resume-platform/pkg/idgen"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Tracing(appName string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
reqId, _ := idgen.GetID()
|
||||
|
||||
ctx := context.WithValue(c.Request.Context(), constant.RequestIdKey, reqId)
|
||||
ctx = context.WithValue(ctx, constant.AppNameKey, appName)
|
||||
ctx = context.WithValue(ctx, constant.RequestRouteKey, c.Request.URL.Path)
|
||||
ctx = context.WithValue(ctx, constant.ClientIP, c.ClientIP())
|
||||
|
||||
c.Request = c.Request.WithContext(ctx)
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user