feat: tool ctx add trace

This commit is contained in:
zhaoyupeng
2025-06-13 16:10:20 +08:00
parent 4eb256bc78
commit f217055e4a

View File

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