Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyOptions ¶
ApplyOptions applies a list of options to the target configuration.
Types ¶
type FunctionalOption ¶
type FunctionalOption[T any] func(*T)
FunctionalOption wraps a function to implement the Option interface. This allows simple functions to be used as options without defining custom types.
Example:
func WithValue(val int) util.Option[MyConfig] {
return util.FunctionalOption[MyConfig](func(cfg *MyConfig) {
cfg.Value = val
})
}
func (FunctionalOption[T]) ApplyTo ¶
func (f FunctionalOption[T]) ApplyTo(target *T)
ApplyTo implements the Option interface for FunctionalOption.
type Option ¶
type Option[T any] interface { ApplyTo(target *T) }
Option is a generic interface for applying configuration to a target. This provides a type-safe way to build functional options for any configuration type.
Example:
type MyConfig struct {
Name string
Value int
}
type MyOption = util.Option[MyConfig]
func WithName(name string) MyOption {
return util.FunctionalOption[MyConfig](func(cfg *MyConfig) {
cfg.Name = name
})
}
Click to show internal directories.
Click to hide internal directories.