context

package
v3.32.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultLogger

func SetDefaultLogger(l logr.Logger)

SetupDefaultLogger sets the package-level global default logger that will be used for Background and TODO contexts.

Types

type CancelFunc

type CancelFunc context.CancelFunc

type Context

type Context interface {
	context.Context
	Logger() logr.Logger
	Parent() context.Context
	SetParent(ctx context.Context) Context
}

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 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 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 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