修复initRequest middleware
This commit is contained in:
parent
ca0cb31235
commit
20d655973a
@ -27,11 +27,12 @@ import (
|
|||||||
// Date : 23:08 2022/6/25
|
// Date : 23:08 2022/6/25
|
||||||
func InitRequest() gin.HandlerFunc {
|
func InitRequest() gin.HandlerFunc {
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
|
httpHandleConfig := define.GetHttpHandleConfig()
|
||||||
traceID := getTraceID(ctx)
|
traceID := getTraceID(ctx)
|
||||||
requestID := getRequestID(ctx, traceID)
|
requestID := getRequestID(ctx, traceID)
|
||||||
ctx.Set(define.TraceIDField, traceID)
|
ctx.Set(httpHandleConfig.TraceIDField, traceID)
|
||||||
ctx.Set(define.RequestIDField, requestID)
|
ctx.Set(httpHandleConfig.RequestIDField, requestID)
|
||||||
ctx.Set(define.StartRequestTimeField, time.Now())
|
ctx.Set(httpHandleConfig.StartRequestTimeField, time.Now())
|
||||||
ctx.Next()
|
ctx.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +58,7 @@ func getTraceID(ctx *gin.Context) string {
|
|||||||
//
|
//
|
||||||
// Date : 23:12 2022/6/25
|
// Date : 23:12 2022/6/25
|
||||||
func getRequestID(ctx *gin.Context, traceID string) string {
|
func getRequestID(ctx *gin.Context, traceID string) string {
|
||||||
requestID := ctx.GetHeader("X-Forward-Request-ID")
|
requestID := ctx.GetHeader("X-Forward-Request-Id")
|
||||||
if len(requestID) > 0 {
|
if len(requestID) > 0 {
|
||||||
return requestID
|
return requestID
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user