Documentation ¶
Overview ¶
Package appctx provides a context.Context based mechanism of sharing certain "global" resources across different parts of an application. When building applications with the github.com/justtrackio/gosoline/pkg/application package a Container is automatically injected into the applications context.
Index ¶
- func Get[T any](ctx context.Context, key any) (T, error)
- func MetadataAppend(ctx context.Context, key string, values ...interface{}) error
- func MetadataSet(ctx context.Context, key string, value interface{}) error
- func Provide[T any](ctx context.Context, key any, factory func() (T, error)) (T, error)
- func WithContainer(ctx context.Context) context.Context
- type ErrNoApplicationContainerFound
- type ErrNoItemFound
- type Metadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶ added in v0.10.0
Get retrieves the value behind key from the container which was injected into ctx by WithContainer. If a new value should be created when none is found for key, use Provide. Returns ErrNoItemFound if key is not present in the container. Returns ErrNoApplicationContainerFound when no container is present in ctx.
func MetadataAppend ¶
MetadataAppend appends the provided values to any existing values at key. The metadata carrier comes from ctx.
func MetadataSet ¶
MetadataSet sets the value for key to the provided value, overwriting any existing value. The metadata carrier comes from ctx.
func Provide ¶
Provide retrieves the value behind key from the container which was injected into ctx by WithContainer. If key is not present in the container the factory will create a new value and store it in the container. This value is then accessible from all other points in a program which have access to the context containing the container. If no new value should be created when none is found for key, use Get. Returns ErrNoApplicationContainerFound when no container is present in ctx.
Types ¶
type ErrNoApplicationContainerFound ¶
type ErrNoApplicationContainerFound struct{}
func (ErrNoApplicationContainerFound) Error ¶
func (e ErrNoApplicationContainerFound) Error() string
type ErrNoItemFound ¶
type ErrNoItemFound struct {
Key interface{}
}
func (ErrNoItemFound) Error ¶
func (e ErrNoItemFound) Error() string
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata provides a thread safe key value store intended to be used with the container injected by WithContainer.
func ProvideMetadata ¶
ProvideMetadata retrieves the metadata carrier from ctx if one is present, else it creates a new one. This is done through Provide, thus having the metadata globally available.
func (*Metadata) Append ¶
Append appends the provided values to any values present at key. If no values are present, they are set to values. If there are already values present no duplicates will be added (the comparison is performed through reflect.DeepEqual).
func (*Metadata) Get ¶
Get retrieves the value node for key. If the key does not exist the data in the node will be empty.
func (*Metadata) Msi ¶
Msi returns a map of all keys to values. Implements the mapx.Msier interface.