25 lines
579 B
Go
25 lines
579 B
Go
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()
|
|
}
|
|
} |