Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CtxKeyType ¶
type CtxKeyType string
CtxKeyType is a type that can be used as a key for a context.Context
type State ¶
type State[T any] struct { CtxKey CtxKeyType }
State is a type that can be used to store data in a context.Context It is useful for storing data that needs to be shared between tests
func NewState ¶
func NewState[T any](opts ...StateOption[T]) *State[T]
NewState creates a new State
Example:
type test struct { Name string } state := state.NewState[test]()
func (*State[T]) Enrich ¶
Enrich enriches the context with the data
Example:
type test struct { Name string } state := state.NewState[test]() ctx := state.Enrich(ctx, &test{ Name: "John", })
type StateOption ¶
StateOption is a type that can be used to configure a State
func WithCtxKey ¶
func WithCtxKey[T any](ctxKey CtxKeyType) StateOption[T]
WithCtxKey is a StateOption that sets the key for the context.Context
Default: default
Example:
type test struct { Name string } state := state.NewState[test]( state.WithCtxKey("test"), )
Click to show internal directories.
Click to hide internal directories.