Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply applies functional options to a config struct.
Example:
cfg := &Config{}
options.Apply(cfg, WithHost("localhost"))
func Merge ¶ added in v1.0.0
func Merge[T any](cfgs ...T) T
Merge combines multiple configurations of the same type. Later values always overwrite earlier ones (LastWins semantics). For SkipZero semantics, use MergeConfig from options_ext.go.
Example:
cfg := options.Merge(defaultCfg, userCfg)
func MergeConfig ¶ added in v1.0.0
func MergeConfig[T any](semantics MergeWithSemantics, cfgs ...T) T
MergeConfig combines configs with explicit merge semantics.
func MustValidate ¶ added in v1.0.0
func MustValidate[T any](cfg T)
MustValidate panics if the struct contains zero-valued required fields. Required fields are marked with `required:"true"` tag.
Types ¶
type Builder ¶
type Builder[T any] struct { // contains filtered or unexported fields }
Builder provides a fluent interface for building config with options.
Example:
cfg := options.NewBuilder(defaultCfg).
With(WithHost("localhost")).
Build()
func NewBuilder ¶
NewBuilder creates a new options builder with default config.
type MergeWithSemantics ¶ added in v1.0.0
type MergeWithSemantics int
MergeWithSemantics controls how Merge handles zero values.
const ( // LastWins means the last config always overwrites, even with zero values. LastWins MergeWithSemantics = iota // SkipZero means zero values in later configs do not overwrite non-zero values. SkipZero )
type Option ¶ added in v0.2.1
type Option[T any] func(*T)
Option is a functional option for configuration.