first commit

This commit is contained in:
2022-03-17 15:59:24 +08:00
commit 2b0debb847
592 changed files with 73946 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package trace
import (
"context"
"github.com/gin-gonic/gin"
"github.com/rs/xid"
)
const DtalkTraceId = "X-dtalk-tracd-id"
func NewTraceIdWithContext(ctx context.Context) string {
logId, ok := ctx.Value(DtalkTraceId).(string)
if !ok {
logId = xid.New().String()
}
return logId
}
func TraceMiddleware() gin.HandlerFunc {
return func(ctx *gin.Context) {
// 或者从 header 中拿
ctx.Set(DtalkTraceId, NewTraceIdWithContext(ctx))
ctx.Next()
}
}