context

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 5 * time.Second

DefaultTimeout 默认超时时间

Variables

This section is empty.

Functions

func GetValue

func GetValue(ctx context.Context, key any) (interface{}, bool)

GetValue 从 context 中获取值

func MustGetValue

func MustGetValue(ctx context.Context, key any) any

MustGetValue 从 context 中获取值,如果不存在则 panic

func NewBaseContext

func NewBaseContext() context.Context

NewBaseContext 初始化基础 context

func WithTimeout

func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeout 派生带超时的 context

func WithValue

func WithValue(parent context.Context, key any, value interface{}) context.Context

WithValue 向 context 中注入值

Types

type ContextKey

type ContextKey string

ContextKey 常量 key,用于存储和提取值

const (
	TraceIDKey ContextKey = "trace_id"
	UserIDKey  ContextKey = "user_id"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL