contextdi

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyDBManager = "_DI_DB_MGR"
)
View Source
const (
	ContextKeyLogger = "_DI_LOGGER"
)
View Source
const (
	ContextKeyMemoise = "_DI_MEMO"
)
View Source
const (
	ContextKeyResponderChain = "_DI_RESPONDER"
)
View Source
const (
	ContextKeyTimedCache = "_DI_TIMEDCACHE"
)

Variables

View Source
var (
	ErrKeyNotFound = errors.Base("value map key not found")
)
View Source
var (
	ErrValueNotDBManager = errors.Base("value is not database.Manager")
)
View Source
var (
	ErrValueNotLogger = errors.Base("value is not logger.Logger")
)
View Source
var (
	ErrValueNotMemoise = errors.Base("value is not memoise.Memoise")
)
View Source
var (
	ErrValueNotResponderChain = errors.Base("value is not responder.Chain")
)
View Source
var (
	ErrValueNotTimedCache = errors.Base("value is not timedcache.TimedCache")
)

Functions

func GetDBManager

func GetDBManager(ctx context.Context) (database.Manager, error)

Get the database manager from the given context.

Will return `ErrValueNoDBManager` if the value in the context is not of type `database.Manager`.

func GetFromContext

func GetFromContext(ctx context.Context, key string) (any, error)

Get a value from a context.

Will signal `contextext.ErrInvalidContext` if the context is not valid. Will signal `contextext.ErrValueMapNotFound` if there is no value map. Will signal `ErrKeyNotFound` if the value map does not contain the key.

func GetLogger

func GetLogger(ctx context.Context) (logger.Logger, error)

Get the logger from the given context.

Will return `ErrValueNotLogger` if the value in the context is not of type `logger.Logger`.

func GetMemoise

func GetMemoise(ctx context.Context) (memoise.Memoise, error)

Get the memoiser from the given context.

Will return `ErrValueNoMemoise` if the value in the context is not of type `memoise.Memoise`.

func GetResponderChain

func GetResponderChain(ctx context.Context) (*responder.Chain, error)

Get the responder chain from the given context.

Will return `ErrValueNotResponderChain` if the value in the context is not of type `responder.Chain`.

Please be aware that this responder chain should be treated as immutable, as we can't really propagate changes down the context hierarchy.

func GetTimedCache

func GetTimedCache(ctx context.Context) (timedcache.TimedCache, error)

Get the timed cache value from the given context.

WIll return `ErrValueNotTimedCache` if the value in the context is not of type `timedcache.TimedCache`.

func MustGetDBManager

func MustGetDBManager(ctx context.Context) database.Manager

Attempt to get the database manager from the given context. Panics if the operation fails.

func MustGetLogger

func MustGetLogger(ctx context.Context) logger.Logger

Attempt to get the logger from the given context. Panics if the operation fails.

func MustGetMemoise

func MustGetMemoise(ctx context.Context) memoise.Memoise

Attempt to get the memoiser from the given context. Panics if the operation fails.

func MustGetResponderChain

func MustGetResponderChain(ctx context.Context) *responder.Chain

Attempt to get the responder chain from the given context. Panics if the operation fails.

func MustGetTimedCache

func MustGetTimedCache(ctx context.Context) timedcache.TimedCache

Attempt to get the timed cache value from the given context. Panics if the operation fails.

func PutToContext

func PutToContext(ctx context.Context, key string, value any) (context.Context, error)

Place a value in a context.

If there is no value map in the context then one will be created.

Returns a new context with the value map.

func SetDBManager

func SetDBManager(ctx context.Context, inst database.Manager) (context.Context, error)

Set the database manager value to the context map.

func SetLogger

func SetLogger(ctx context.Context, inst logger.Logger) (context.Context, error)

Set the logger value to the context map.

func SetMemoise

func SetMemoise(ctx context.Context, inst memoise.Memoise) (context.Context, error)

Set the memoiser value to the context map.

func SetResponderChain

func SetResponderChain(ctx context.Context, inst *responder.Chain) (context.Context, error)

Set the responder chain value in the context map.

func SetTimedCache

func SetTimedCache(ctx context.Context, inst timedcache.TimedCache) (context.Context, error)

Set the timed cache value in the context map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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