Documentation ¶
Index ¶
- type Context
- func Background() *Context
- func ErrGroup(ctx *Context) (*errgroup.Group, *Context)
- func FromGrpcCtx(ctx context.Context) *Context
- func New(ctx context.Context, log *logrus.Entry) *Context
- func TODO() *Context
- func WithCancel(parent *Context) (*Context, context.CancelFunc)
- func WithDeadline(parent *Context, d time.Time) (*Context, context.CancelFunc)
- func WithLogField(parent *Context, key string, val interface{}) *Context
- func WithLogFields(parent *Context, fields logrus.Fields) *Context
- func WithTimeout(parent *Context, timeout time.Duration) (*Context, context.CancelFunc)
- func WithValue(parent *Context, key, val any) *Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { context.Context logrus.FieldLogger }
Context is an extension of Go's context which also includes a logger. This allows us to pass round a contextual logger while retaining type-safety
func Background ¶
func Background() *Context
Background creates an empty context with a default logger. It is analogous to context.Background()
func ErrGroup ¶
ErrGroup returns a new Error Group and an associated Context derived from ctx. It is analogous to errgroup.WithContext(ctx)
func FromGrpcCtx ¶
FromGrpcCtx creates a context where the logger is extracted via ctxlogrus's Extract() method. Note that this will result in a no-op logger if a logger hasn't already been inserted into the context via ctxlogrus
func TODO ¶
func TODO() *Context
TODO creates an empty context with a default logger. It is analogous to context.TODO()
func WithCancel ¶
func WithCancel(parent *Context) (*Context, context.CancelFunc)
WithCancel returns a copy of parent with a new Done channel. It is analogous to context.WithCancel()
func WithDeadline ¶
WithDeadline returns a copy of the parent context with the deadline adjusted to be no later than d. It is analogous to context.WithDeadline()
func WithLogField ¶
WithLogField returns a copy of parent with the supplied key-value added to the logger
func WithLogFields ¶
WithLogFields returns a copy of parent with the supplied key-values added to the logger
func WithTimeout ¶
WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). It is analogous to context.WithTimeout()