context

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 3 Imported by: 6

Documentation

Overview

Package context contains generated code by adptool.

Package context provides the context functions

Package context provides the context functions

Index

Constants

This section is empty.

Variables

View Source
var (
	Canceled         = context.Canceled
	DeadlineExceeded = context.DeadlineExceeded
)

Functions

func AfterFunc

func AfterFunc(ctx context.Context, f func()) (stop func() bool)

func Background

func Background() context.Context

func Cause

func Cause(c context.Context) error

func FromCreatedBy

func FromCreatedBy(ctx Context) string

FromCreatedBy retrieves the creator information from the given context.

It takes a Context as a parameter and returns a string.

func FromDB

func FromDB(ctx Context) (any, bool)

FromDB retrieves a db client from the context.

It takes a Context as a parameter and returns a db client.

func FromID

func FromID(ctx Context) string

FromID returns the user ID from the context.

It takes a Context as a parameter and returns a string.

func FromMapContext

func FromMapContext(parent Context) map[any]any

FromMapContext retrieves all values from the context.

func FromRowLock

func FromRowLock(ctx Context) bool

FromRowLock checks if the row is locked in the given context.

It takes a Context as a parameter and returns a boolean.

func FromSpan

func FromSpan(ctx Context) string

FromSpan returns the span id from the context.

It takes a Context as a parameter and returns a string.

func FromStack

func FromStack(ctx Context) string

FromStack retrieves the stack from the context.

It takes a Context as a parameter and returns a string.

func FromTag

func FromTag(ctx Context) string

FromTag retrieves the tag from the context.

It takes a Context as a parameter and returns a string.

func FromToken

func FromToken(ctx Context) string

FromToken returns the user token from the context.

It takes a Context as a parameter and returns a string.

func FromTrace

func FromTrace(ctx Context) string

FromTrace returns the trace id from the context.

It takes a Context as a parameter and returns a string.

func FromTrans

func FromTrans(ctx Context) (any, bool)

FromTrans retrieves a tx client from the context.

func FromUserCache

func FromUserCache(ctx Context) (any, bool)

FromUserCache returns the userCache from the context.

It takes a Context as a parameter and returns a userCache value.

func IsNameSkipped added in v0.2.3

func IsNameSkipped(ctx Context, name string) bool

IsNameSkipped checks if the context is skipped by name. It takes a Context and a name string as parameters and returns a boolean. The skip value is used to skip the middleware.

Example usage:

if context.IsNameSkipped(ctx, "name") {
	return
}

func IsSkipped added in v0.2.2

func IsSkipped(ctx Context) bool

IsSkipped checks if the context is skipped. It takes a Context as a parameter and returns a boolean. The skip value is used to skip the middleware.

Example usage:

if context.IsSkipped(ctx) {
	return
}

func TODO

func TODO() context.Context

func Value

func Value(ctx Context, key any) any

Value retrieves the value for the given key or nil if no value is present.

func WithCancel

func WithCancel(parent context.Context) (ctx context.Context, cancel context.CancelFunc)

func WithCancelCause

func WithCancelCause(parent context.Context) (ctx context.Context, cancel context.CancelCauseFunc)

func WithDeadline

func WithDeadline(parent context.Context, d time.Time) (context.Context, context.CancelFunc)

func WithDeadlineCause

func WithDeadlineCause(parent context.Context, d time.Time, cause error) (context.Context, context.CancelFunc)

func WithTimeout

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

func WithTimeoutCause

func WithTimeoutCause(parent context.Context, timeout time.Duration, cause error) (context.Context, context.CancelFunc)

func WithValue

func WithValue(parent context.Context, key, val any) context.Context

func WithoutCancel

func WithoutCancel(parent context.Context) context.Context

Types

type CancelCauseFunc

type CancelCauseFunc = context.CancelCauseFunc

type CancelFunc

type CancelFunc = context.CancelFunc

type Context

type Context = context.Context

func NewCreatedBy

func NewCreatedBy(ctx Context, by string) Context

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

func NewDB(ctx Context, db any) Context

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

func NewID(ctx Context, id string) Context

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 NewNamedSkip added in v0.2.3

func NewNamedSkip(ctx Context, name ...string) Context

NewNamedSkip creates a new context with the skip value and name. It takes a context and a name string as parameters and returns a context. The skip value is used to skip the middleware.

Example usage:

ctx := context.NewNamedSkip(ctx, "name")

func NewRowLock

func NewRowLock(ctx Context) Context

NewRowLock creates a new context with a row lock value.

func NewSkip added in v0.2.2

func NewSkip(ctx Context) Context

NewSkip creates a new context with the skip value. It takes a context as a parameter and returns a context. The skip value is used to skip the middleware.

Example usage:

ctx := context.NewSkip(ctx)

func NewSpan

func NewSpan(ctx Context, span string) Context

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

func NewStack(ctx Context, stack string) Context

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

func NewTag(ctx Context, tag string) Context

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

func NewToken(ctx Context, token string) Context

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

func NewTrace(ctx Context, trace string) Context

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 NewTrans

func NewTrans(ctx Context, tx any) Context

NewTrans creates a new context with the provided tx client value.

func NewUserCache

func NewUserCache(ctx Context, userCache any) Context

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 WithContext

func WithContext(ctxs ...Context) Context

WithContext returns a new context with the provided context.Context value. It takes a variadic parameter of type Context and returns a Context. If no contexts are provided, it returns a background context. Otherwise, it returns the first context in the variadic parameter.

Example usage:

ctx := context.WithContext(ctx1, ctx2, ctx3)

or

ctx := context.WithContext()

func WithMapValue

func WithMapValue(parent Context, key, val any) Context

WithMapValue creates a new context with the provided key-value pair. If the context saved over than 500 keys, use WithMapValue instead.

Jump to

Keyboard shortcuts

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