提交 f090300d authored 作者: mooncake9527's avatar mooncake9527

修改

上级 5e04fef8
...@@ -12,14 +12,11 @@ import ( ...@@ -12,14 +12,11 @@ import (
) )
const ( const (
GinContextKey = "gin_context" GinContextKey = "ginContext"
KeyConfigFile = "config_file"
KeyConfigCenter = "config_center"
HeaderXTimestampKey = "Timestamp" HeaderXTimestampKey = "Timestamp"
KeyReqBody = "req-body" KeyReqBody = "reqBody"
KeyRspBody = "rsp-body" KeyRspBody = "rspBody"
KeyTid = "tid" KeyClientIP = "clientIP"
KeyClientIP = "client_ip"
KeyUID = "userId" KeyUID = "userId"
KeyUType = "userType" KeyUType = "userType"
KeyCompanyID = "companyId" KeyCompanyID = "companyId"
...@@ -115,10 +112,10 @@ func GetCtxUserToken(c context.Context) string { ...@@ -115,10 +112,10 @@ func GetCtxUserToken(c context.Context) string {
} }
func GetGinCtxTid(c *gin.Context) string { func GetGinCtxTid(c *gin.Context) string {
tid := c.GetString(KeyTid) tid := c.GetString(ContextTraceIDKey)
if tid == "" { if tid == "" {
tid = GenerateTid() tid = GenerateTid()
c.Set(KeyTid, tid) c.Set(ContextTraceIDKey, tid)
} }
return tid return tid
} }
...@@ -129,7 +126,7 @@ func GenerateTid() string { ...@@ -129,7 +126,7 @@ func GenerateTid() string {
func GetCtxTid(ctx context.Context) string { func GetCtxTid(ctx context.Context) string {
tid := "" tid := ""
tidVal := ctx.Value(KeyTid) tidVal := ctx.Value(ContextTraceIDKey)
if tidVal != nil { if tidVal != nil {
if str, ok := tidVal.(string); ok { if str, ok := tidVal.(string); ok {
tid = str tid = str
......
...@@ -28,7 +28,7 @@ func NewCustomGormLogger(l *zap.Logger, requestIDKey string, logLevel logger.Log ...@@ -28,7 +28,7 @@ func NewCustomGormLogger(l *zap.Logger, requestIDKey string, logLevel logger.Log
l, _ = zap.NewProduction() l, _ = zap.NewProduction()
} }
if requestIDKey == "" { if requestIDKey == "" {
requestIDKey = "traceID" requestIDKey = "X-Request-ID"
} }
if logLevel == 0 { if logLevel == 0 {
logLevel = logger.Info logLevel = logger.Info
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论