context

package
v3.63.7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause added in v3.54.2

func Cause(ctx context.Context) error

Cause returns the context.Cause of the context.

func SetDefaultLogger

func SetDefaultLogger(l logr.Logger)

SetupDefaultLogger sets the package-level global default logger that will be used for Background and TODO contexts. On startup, the default logger will be configured to output logs to stderr. Use logr.Discard() to disable all logs from Contexts.

Types

type CancelCauseFunc added in v3.54.2

type CancelCauseFunc = context.CancelCauseFunc

type CancelFunc

type CancelFunc = context.CancelFunc

CancelFunc and CancelCauseFunc are type aliases to allow use as if they are the same types as the standard library variants.

type Context

type Context interface {
	context.Context
	Logger() logr.Logger
}

Context wraps context.Context and includes an additional Logger() method.

func AddLogger

func AddLogger(parent context.Context) Context

AddLogger converts a context.Context into a Context. If the underlying type is already a Context, that will be returned, otherwise a default logger will be added.

func Background

func Background() Context

Background returns context.Background with a default logger.

func TODO

func TODO() Context

TODO returns context.TODO with a default logger.

func WithCancel

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

WithCancel returns context.WithCancel with the log object propagated.

func WithCancelCause added in v3.54.2

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

WithCancelCause returns context.WithCancelCause with the log object propagated.

func WithDeadline

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

WithDeadline returns context.WithDeadline with the log object propagated and the deadline added to the structured log values.

func WithDeadlineCause added in v3.54.2

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

WithDeadlineCause returns context.WithDeadlineCause with the log object propagated and the deadline added to the structured log values.

func WithLogger

func WithLogger(parent context.Context, logger logr.Logger) Context

WithLogger converts a context.Context into a Context by adding a logger.

func WithTimeout

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

WithTimeout returns context.WithTimeout with the log object propagated and the timeout added to the structured log values.

func WithTimeoutCause added in v3.54.2

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

WithTimeoutCause returns context.WithTimeoutCause with the log object propagated and the timeout added to the structured log values.

func WithValue

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

WithValue returns context.WithValue with the log object propagated and the value added to the structured log values (if the key is a string).

func WithValues

func WithValues(parent Context, keyAndVals ...any) Context

WithValues returns context.WithValue with the log object propagated and the values added to the structured log values (if the key is a string).

Jump to

Keyboard shortcuts

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