ctx

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 2 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CTX

type CTX struct {
	context.Context
	logrus.FieldLogger
}

CTX extends the standard context from the standard library, integrating it with the logrus package for structured logging. It allows passing around a single object in function calls that provides both context management (like cancellation and timeouts) and the ability to log structured data.

func Background

func Background() CTX

Background returns a non-nil, empty Context. It is typically used for initialization and in situations where there is no existing context (like in the main function or tests).

func WithCancel

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

WithCancel creates a new CTX and a cancel function from the provided parent CTX. The cancel function, when called, cancels the new CTX, releasing any resources associated with it, such as child goroutines waiting on the CTX's Done channel.

func WithValue

func WithValue(parent CTX, key string, val interface{}) CTX

WithValue returns a copy of the parent for adding metadata to the context and logs, which can then be passed down through function calls.

func WithValues

func WithValues(parent CTX, kvs map[string]interface{}) CTX

WithValues is similar to WithValue, but allows adding multiple key-value pairs at once.

Jump to

Keyboard shortcuts

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