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.
func Cause ¶
Cause returns the underlying cause of the context's cancellation or nil if it was not caused by another error.
func FromCreatedBy ¶
FromCreatedBy retrieves the creator information from the given context.
It takes a Context as a parameter and returns a string.
func FromDB ¶
FromDB retrieves a db client from the context.
It takes a Context as a parameter and returns a db client.
func FromID ¶
FromID returns the user ID from the context.
It takes a Context as a parameter and returns a string.
func FromMapContext ¶
FromMapContext retrieves all values from the context.
func FromRowLock ¶
FromRowLock checks if the row is locked in the given context.
It takes a Context as a parameter and returns a boolean.
func FromSpan ¶
FromSpan returns the span id from the context.
It takes a Context as a parameter and returns a string.
func FromStack ¶
FromStack retrieves the stack from the context.
It takes a Context as a parameter and returns a string.
func FromTag ¶
FromTag retrieves the tag from the context.
It takes a Context as a parameter and returns a string.
func FromToken ¶
FromToken returns the user token from the context.
It takes a Context as a parameter and returns a string.
func FromTrace ¶
FromTrace returns the trace id from the context.
It takes a Context as a parameter and returns a string.
func FromUserCache ¶
FromUserCache returns the userCache from the context.
It takes a Context as a parameter and returns a userCache value.
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.
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.
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.
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.
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.
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.
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.
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.
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.
func NewID ¶
NewID returns a new context with the provided userID value.
It takes a context and a userID string as parameters and returns a context.
func NewRowLock ¶
NewRowLock creates a new context with a row lock value.
func NewSpan ¶
NewSpan creates a new context with the provided span value.
It takes a context and a span string as parameters and returns a context.
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.
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.
func NewToken ¶
NewToken returns a new context with the provided userToken value.
It takes a context and a userToken string as parameters and returns a context.
func NewTrace ¶
NewTrace returns a new context with the provided trace value.
It takes a context and a trace string as parameters and returns a context.
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.
func TODO ¶
func TODO() Context
TODO returns an empty Context. It is never canceled, has no deadline, and has no values.
func WithContext ¶
WithContext returns a new context with the provided context.Context value.
func WithMapValue ¶
WithMapValue creates a new context with the provided key-value pair. If the context saved over than 500 keys, use WithMapValue 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.
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.