feat: v2 版本 #206

Merged
huanghaosheng merged 201 commits from v2 into main 2026-06-22 16:01:28 +08:00
Showing only changes of commit a02a8bc374 - Show all commits

View File

@@ -0,0 +1,17 @@
package trace
import "github.com/gin-gonic/gin"
// TraceMiddleware 为每个 HTTP 请求生成 trace ID 并注入 context
func TraceMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
traceID := GenerateTraceID()
ctx := WithTraceID(c.Request.Context(), traceID)
ctx = WithRequestID(ctx, traceID) // REST: trace_id == request_id
c.Request = c.Request.WithContext(ctx)
c.Header("X-Trace-ID", traceID) // 返回给客户端用于排查
c.Next()
}
}