diff --git a/tool/ctx.go b/tool/ctx.go index 82242a3..e5320c1 100644 --- a/tool/ctx.go +++ b/tool/ctx.go @@ -2,6 +2,8 @@ package tool import ( "context" + "fmt" + "gitea.loveuer.com/yizhisec/packages/opt" "time" ) @@ -21,7 +23,7 @@ func Timeout(seconds ...int) (ctx context.Context) { return } -func TimeoutCtx(ctx context.Context, seconds ...int) context.Context { +func CtxTimeout(ctx context.Context, seconds ...int) context.Context { var ( duration time.Duration ) @@ -36,3 +38,7 @@ func TimeoutCtx(ctx context.Context, seconds ...int) context.Context { return nctx } + +func CtxTrace(ctx context.Context, key string) context.Context { + return context.WithValue(ctx, opt.TraceKey, fmt.Sprintf("%36s", key)) +}