ctx

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReusableContext

type ReusableContext[K comparable, V any] interface {
	context.Context
	Set(parent context.Context, key K, value V)
}

func NewReusable

func NewReusable[K comparable, V any]() ReusableContext[K, V]

func WithValue

func WithValue[K comparable, V any](parent context.Context, key K, val V) ReusableContext[K, V]

WithValue returns a copy of parent in which the value associated with key is val.

Use context Values only for request-scoped data that transits processes and APIs, not for passing optional parameters to functions.

The provided key must be comparable and should not be of type string or any other built-in type to avoid collisions between packages using context. Users of WithValue should define their own types for keys. To avoid allocating when assigning to an interface{}, context keys often have concrete type struct{}. Alternatively, exported context key variables' static type should be a pointer or interface.

type ValueCtx

type ValueCtx[K comparable, V any] struct {
	context.Context
	// contains filtered or unexported fields
}

ValueCtx carries a key-value pair. It implements Value for that key and delegates all other calls to the embedded Context.

func (*ValueCtx[K, V]) Set

func (v *ValueCtx[K, V]) Set(parent context.Context, key K, value V)

func (*ValueCtx[K, V]) String

func (v *ValueCtx[K, V]) String() string

func (*ValueCtx[K, V]) Value

func (v *ValueCtx[K, V]) Value(key any) any

Jump to

Keyboard shortcuts

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