From 1f6e904bab661c12f3081f0860e4bd8eba194ad9 Mon Sep 17 00:00:00 2001 From: axiaoxin <254606826@qq.com> Date: Thu, 19 Nov 2020 17:43:14 +0800 Subject: [PATCH] =?UTF-8?q?CtxTraceID=20=E5=B0=9D=E8=AF=95=E5=85=85gin=20q?= =?UTF-8?q?uerystring=20=E6=88=96=E8=AF=B7=E6=B1=82json=20body=E4=B8=AD?= =?UTF-8?q?=E8=8E=B7=E5=8F=96traceid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- context.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/context.go b/context.go index ffc6482..b887b4d 100644 --- a/context.go +++ b/context.go @@ -6,6 +6,7 @@ import ( "context" "github.com/gin-gonic/gin" + jsoniter "github.com/json-iterator/go" "github.com/rs/xid" "go.uber.org/zap" ) @@ -58,6 +59,13 @@ func CtxTraceID(c context.Context) string { if traceID := gc.GetString(string(TraceIDKeyname)); traceID != "" { return traceID } + if traceID := gc.Query(string(TraceIDKeyname)); traceID != "" { + return traceID + } + if traceID := jsoniter.Get(GetGinRequestBody(gc), string(TraceIDKeyname)).ToString(); traceID != "" { + return traceID + } + } // get from go context traceIDItf := c.Value(TraceIDKeyname)