- update get

master v1.0.1
李光春 2 years ago
parent 28daa77389
commit 6b30aded32

@ -1,3 +1,3 @@
package gotrace_id
const Version = "1.0.0"
const Version = "1.0.1"

@ -2,7 +2,6 @@ package gotrace_id
import (
"context"
"fmt"
"github.com/gin-gonic/gin"
"go.dtapp.net/gostring"
)
@ -19,5 +18,5 @@ func SetGinTraceIdContext(c *gin.Context) context.Context {
// GetTraceIdContext 通过上下文获取跟踪编号
func GetTraceIdContext(ctx context.Context) string {
return fmt.Sprintf("%s", ctx.Value("trace_id"))
return ctx.Value("trace_id").(string)
}

@ -1,16 +1,11 @@
package gotrace_id
import (
"context"
"testing"
)
func TestContext(t *testing.T) {
ctx := context.Background()
ctx := CustomTraceIdContext()
t.Log(ctx)
ctx = context.WithValue(ctx, "k1", "测试")
t.Log()
t.Log(GetTraceIdContext(ctx))
}

@ -1,7 +1,6 @@
package gotrace_id
import (
"fmt"
"github.com/gin-gonic/gin"
"go.dtapp.net/gostring"
)
@ -21,5 +20,5 @@ func SetGinTraceId() gin.HandlerFunc {
// GetGinTraceId 通过gin中间件获取跟踪编号
func GetGinTraceId(c *gin.Context) string {
return fmt.Sprintf("%s", c.MustGet("trace_id"))
return c.MustGet("trace_id").(string)
}

Loading…
Cancel
Save