pctx

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 2 Imported by: 0

README

go-pctx

persisted context values across both directions of a callstack.

there will be strictly no piss jokes here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Persist

func Persist(ctx context.Context, key any, value any) context.Context

Persist will store the key-value pair in provided context. Either wrapping it in a persistent context that supports multiple value storage, or digging through the context stack for an existing persistent context into which it will store the key-value pair. This allows storing and accessing context values across multiple layers of a callstack, both forwards and backwards.

Types

type PersistCtx

type PersistCtx struct {
	// embedded base ctx.
	context.Context
	// contains filtered or unexported fields
}

persistctx wraps a base context.Context in order to provide persistent key-value storage across both directions of a callstack.

func Get

func Get(ctx context.Context) *PersistCtx

Get will wrap the provided context in a PersistCtx, or return an existing copy if found in the context stack.

func (*PersistCtx) Set

func (ctx *PersistCtx) Set(key any, value any)

Set will safely set the key-value pair in context "map".

func (*PersistCtx) Value

func (ctx *PersistCtx) Value(key any) any

Value implements context.Context's Value().

Jump to

Keyboard shortcuts

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