Documentation
¶
Index ¶
- Constants
- func GetValue(ctx context.Context, key any) (interface{}, bool)
- func MustGetValue(ctx context.Context, key any) any
- func NewBaseContext() context.Context
- func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func WithValue(parent context.Context, key any, value interface{}) context.Context
- type ContextKey
Constants ¶
View Source
const DefaultTimeout = 5 * time.Second
DefaultTimeout 默认超时时间
Variables ¶
This section is empty.
Functions ¶
func MustGetValue ¶
MustGetValue 从 context 中获取值,如果不存在则 panic
func WithTimeout ¶
func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
WithTimeout 派生带超时的 context
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey 常量 key,用于存储和提取值
const ( TraceIDKey ContextKey = "trace_id" UserIDKey ContextKey = "user_id" )
Click to show internal directories.
Click to hide internal directories.