optionutil

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package optionutil provides utility functions for working with options.Context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[T any](ctx options.Context, values ...T) options.Context

Append appends values to a slice using an implicit key.

func Apply

func Apply[T any](cfg *T, opts ...options.Option) options.Context

Apply applies a series of options.Option to a given configuration object.

func Default

func Default() options.Context

Default creates a default options.Context instance.

func Empty

func Empty() options.Context

Empty creates an empty options.Context instance.

func New

func New[T any](opts ...options.Option) (options.Context, *T)

New creates a new instance of T, applies options, and returns both the final context and the configured instance.

func NewContext

func NewContext[T any](opts ...options.Option) options.Context

NewContext creates a new instance of T, applies options, and returns the resulting context.

func NewT

func NewT[T any](opts ...options.Option) *T

NewT creates a new instance of T, applies options, and returns the configured instance.

func Slice

func Slice[T any](ctx options.Context) []T

Slice retrieves a slice using an implicit key.

func SliceCond

func SliceCond[T any](ctx options.Context, condition func([]T) bool) []T

func SliceOr

func SliceOr[T any](ctx options.Context, defaultValue []T) []T

SliceOr retrieves a slice, or a default if not found.

func Update

func Update[T any](updaters ...func(*T)) options.Option

Update returns an options.Option that modifies a configuration struct *T using an implicit key.

func Value

func Value[T any](ctx options.Context) (T, bool)

Value retrieves a value using an implicit key.

func ValueCond

func ValueCond[T any](ctx options.Context, condition func(T) bool, defaultValue T) T

ValueCond retrieves a value if the condition is true, or a default otherwise.

func ValueOr

func ValueOr[T any](ctx options.Context, defaultValue T) T

ValueOr retrieves a value, or a default if not found.

func WithCond

func WithCond(condition bool, opt options.Option) options.Option

WithCond returns an options.Option that applies the given options.Option if the condition is true.

func WithContext

func WithContext(ctx options.Context) options.Option

WithContext returns an options.Option that sets the given options.Context as the current context.

func WithGroup

func WithGroup(opts ...options.Option) options.Option

WithGroup returns an options.Option that applies a group of options.Option to the context.

func WithValue

func WithValue[T any](ctx options.Context, value T) options.Context

WithValue sets a value using an implicit key.

Types

type Key

type Key[T any] struct{}

Key is a generic struct used as a type-safe identifier for option keys. It ensures type safety when storing and retrieving values from options.Context.

Jump to

Keyboard shortcuts

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