Documentation
¶
Overview ¶
Package context provides the context functions
Package context provides the context functions
Index ¶
- func AfterFunc(ctx Context, f func()) func() bool
- func Cause(ctx Context) error
- func FromCreatedBy(ctx Context) string
- func FromDB(ctx Context) (any, bool)
- func FromID(ctx Context) string
- func FromMapContext(parent Context) map[any]any
- func FromRowLock(ctx Context) bool
- func FromSpan(ctx Context) string
- func FromStack(ctx Context) string
- func FromTag(ctx Context) string
- func FromToken(ctx Context) string
- func FromTrace(ctx Context) string
- func FromTrans(ctx Context) (any, bool)
- func FromUserCache(ctx Context) (any, bool)
- func Value(ctx Context, key any) any
- func WithCancel(parent Context) (Context, CancelFunc)
- func WithCancelCause(parent Context) (Context, CancelCauseFunc)
- func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc)
- func WithDeadlineCause(parent Context, deadline time.Time, cause error) (Context, CancelFunc)
- func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc)
- func WithTimeoutCause(parent Context, timeout time.Duration, cause error) (Context, CancelFunc)
- type CancelCauseFunc
- type CancelFunc
- type Context
- func Background() Context
- func NewCreatedBy(ctx Context, by string) Context
- func NewDB(ctx Context, db any) Context
- func NewID(ctx Context, id string) Context
- func NewRowLock(ctx Context) Context
- func NewSpan(ctx Context, span string) Context
- func NewStack(ctx Context, stack string) Context
- func NewTag(ctx Context, tag string) Context
- func NewToken(ctx Context, token string) Context
- func NewTrace(ctx Context, trace string) Context
- func NewTrans(ctx Context, tx any) Context
- func NewUserCache(ctx Context, userCache any) Context
- func TODO() Context
- func WithContext(ctx Context) Context
- func WithMapValue(parent Context, key, val any) Context
- func WithValue(parent Context, key, val any) Context
- func WithoutCancel(parent Context) Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AfterFunc ¶
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. If the context is canceled before the duration elapses, f will not be called. Deprecated: Use runtime.context instead.
func Cause ¶
Cause returns the underlying cause of the context's cancellation or nil if it was not caused by another error. Deprecated: Use runtime.context instead.
func FromCreatedBy ¶
FromCreatedBy retrieves the creator information from the given context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromDB ¶
FromDB retrieves a db client from the context.
It takes a Context as a parameter and returns a db client. Deprecated: Use runtime.context instead.
func FromID ¶ added in v0.0.42
FromID returns the user ID from the context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromMapContext ¶ added in v0.0.38
FromMapContext retrieves all values from the context. Deprecated: Use runtime.context instead.
func FromRowLock ¶
FromRowLock checks if the row is locked in the given context.
It takes a Context as a parameter and returns a boolean. Deprecated: Use runtime.context instead.
func FromSpan ¶ added in v0.0.58
FromSpan returns the span id from the context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromStack ¶
FromStack retrieves the stack from the context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromTag ¶
FromTag retrieves the tag from the context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromToken ¶ added in v0.0.42
FromToken returns the user token from the context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromTrace ¶ added in v0.0.42
FromTrace returns the trace id from the context.
It takes a Context as a parameter and returns a string. Deprecated: Use runtime.context instead.
func FromTrans ¶
FromTrans retrieves a tx client from the context. Deprecated: Use runtime.context instead.
func FromUserCache ¶
FromUserCache returns the userCache from the context.
It takes a Context as a parameter and returns a userCache value. Deprecated: Use runtime.context instead.
func Value ¶ added in v0.0.38
Value retrieves the value for the given key or nil if no value is present. Deprecated: Use runtime.context instead.
func WithCancel ¶
func WithCancel(parent Context) (Context, CancelFunc)
WithCancel returns a copy of the parent Context with a new Done channel. The returned context's Done channel is closed when the returned cancel function is called or when the parent context's Done channel is closed, whichever happens first. Deprecated: Use runtime.context instead.
func WithCancelCause ¶
func WithCancelCause(parent Context) (Context, CancelCauseFunc)
WithCancelCause returns a copy of the parent Context with a new Done channel and an associated cause. The returned context's Done channel is closed when the returned cancel function is called, when the parent context's Done channel is closed, or when the provided cause is returned by the parent context's Err method, whichever happens first. Deprecated: Use runtime.context instead.
func WithDeadline ¶
func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc)
WithDeadline returns a copy of the parent Context with a deadline adjusted to be no later than d. If the parent's deadline is already earlier than d, WithDeadline(parent, d) is semantically equivalent to parent. The returned context's Done channel is closed when the deadline expires, when the returned cancel function is called, or when the parent context's Done channel is closed, whichever happens first. Deprecated: Use runtime.context instead.
func WithDeadlineCause ¶
WithDeadlineCause returns a copy of the parent Context with a deadline adjusted to be no later than d and an associated cause. If the parent's deadline is already earlier than d, WithDeadlineCause(parent, d) is semantically equivalent to parent. The returned context's Done channel is closed when the deadline expires, when the returned cancel function is called, or when the provided cause is returned by the parent context's Err method, whichever happens first. Deprecated: Use runtime.context instead.
func WithTimeout ¶
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc)
WithTimeout returns a copy of the parent Context with a deadline adjusted to be no later than when the duration d elapses. It is equivalent to WithDeadline(parent, time.Now().Add(d)). The returned context's Done channel is closed when the timeout elapses, when the returned cancel function is called, or when the parent context's Done channel is closed, whichever happens first. Deprecated: Use runtime.context instead.
func WithTimeoutCause ¶
WithTimeoutCause returns a copy of the parent Context with a deadline adjusted to be no later than when the duration d elapses and an associated cause. It is equivalent to WithDeadline(parent, time.Now().Add(d)). The returned context's Done channel is closed when the timeout elapses, when the returned cancel function is called, or when the provided cause is returned by the parent context's Err method, whichever happens first. Deprecated: Use runtime.context instead.
Types ¶
type CancelCauseFunc ¶
type CancelCauseFunc = context.CancelCauseFunc
All context types are defined in the context package.
type CancelFunc ¶
type CancelFunc = context.CancelFunc
All context types are defined in the context package.
type Context ¶
All context types are defined in the context package.
func Background ¶
func Background() Context
Background returns a non-nil, empty Context. It is never canceled, has no deadline, and has no values. Background is typically used by the main function, initialization, and tests, and as the top-level Context for incoming requests. Deprecated: Use runtime.context instead.
func NewCreatedBy ¶
NewCreatedBy creates a new context with the provided 'by' value
It takes a Context and a 'by' string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewDB ¶
NewDB creates a new context with the provided db client value.
It takes a context and a db client as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewID ¶ added in v0.0.42
NewID returns a new context with the provided userID value.
It takes a context and a userID string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewRowLock ¶
NewRowLock creates a new context with a row lock value. Deprecated: Use runtime.context instead.
func NewSpan ¶ added in v0.0.58
NewSpan creates a new context with the provided span value.
It takes a context and a span string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewStack ¶
NewStack creates a new context with the provided stack value.
It takes a Context and a stack string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewTag ¶
NewTag creates a new context with the provided tag value.
It takes a Context and a tag string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewToken ¶ added in v0.0.42
NewToken returns a new context with the provided userToken value.
It takes a context and a userToken string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewTrace ¶ added in v0.0.42
NewTrace returns a new context with the provided trace value.
It takes a context and a trace string as parameters and returns a context. Deprecated: Use runtime.context instead.
func NewTrans ¶
NewTrans creates a new context with the provided tx client value. Deprecated: Use runtime.context instead.
func NewUserCache ¶
NewUserCache returns a new context with the provided userCache value.
It takes a Context and a userCache value as parameters and returns a context. Deprecated: Use runtime.context instead.
func TODO ¶
func TODO() Context
TODO returns an empty Context. It is never canceled, has no deadline, and has no values. Deprecated: Use runtime.context instead.
func WithContext ¶ added in v0.0.38
WithContext returns a new context with the provided context.Context value. Deprecated: Use runtime.context instead.
func WithMapValue ¶ added in v0.0.38
WithMapValue creates a new context with the provided key-value pair. If the context saved over than 500 keys, use WithMapValue instead. Deprecated: Use runtime.context instead.
func WithValue ¶
WithValue returns a copy of the parent Context that carries the given key-value pair. The value's type must be comparable for equality; otherwise, WithValue will panic. Use context Values only for request-scoped data that transits processes and API boundaries, not for passing optional parameters to functions. Deprecated: Use runtime.context instead.
func WithoutCancel ¶
WithoutCancel returns a non-cancellable Context derived from parent. It is never canceled, has no deadline, and has the same values as the parent. If the parent is already non-cancellable, WithoutCancel returns the parent. Deprecated: Use runtime.context instead.