Documentation
¶
Overview ¶
Package optionutil provides utility functions for working with options.Context.
Index ¶
- func Append[T any](ctx options.Context, values ...T) options.Context
- func Apply[T any](cfg *T, opts ...options.Option) options.Context
- func ApplyContext(ctx context.Context, opts ...options.Option) context.Context
- func Context(ctx context.Context) options.Context
- func Default() options.Context
- func Empty() options.Context
- func FromContext(ctx context.Context) []options.Option
- func New[T any](opts ...options.Option) (options.Context, *T)
- func NewContext[T any](opts ...options.Option) options.Context
- func NewT[T any](opts ...options.Option) *T
- func Slice[T any](ctx options.Context) []T
- func SliceCond[T any](ctx options.Context, condition func([]T) bool) []T
- func SliceOr[T any](ctx options.Context, defaultValue []T) []T
- func Update[T any](updaters ...func(*T)) options.Option
- func Value[T any](ctx options.Context) (T, bool)
- func ValueCond[T any](ctx options.Context, condition func(T) bool, defaultValue T) T
- func ValueOr[T any](ctx options.Context, defaultValue T) T
- func WithCond(condition bool, opt options.Option) options.Option
- func WithContext(ctx options.Context) options.Option
- func WithGroup(opts ...options.Option) options.Option
- func WithOption(ctx context.Context, opts ...options.Option) context.Context
- func WithValue[T any](ctx options.Context, value T) options.Context
- type Key
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyContext ¶
ApplyContext applies a series of options.Option to a standard context.Context. Optimized: Uses ctxValue to bridge the two context worlds without overhead.
func FromContext ¶
FromContext retrieves options from the standard context.
func New ¶
New creates a new instance of T, applies options, and returns both the final context and the configured instance.
func NewContext ¶
NewContext creates a new instance of T, applies options, and returns the resulting context.
func Update ¶
Update returns an options.Option that modifies a configuration struct *T using an implicit key.
func WithCond ¶
WithCond returns an options.Option that applies the given options.Option if the condition is true.
func WithContext ¶
WithContext returns an options.Option that sets the given options.Context as the current context.
func WithGroup ¶
WithGroup returns an options.Option that applies a group of options.Option to the context.
func WithOption ¶
WithOption adds options to the standard context. Optimized: Directly uses the identity storage of context.Context.