Documentation
¶
Overview ¶
Package settings provides type-safe configuration management with default value handling.
Package settings implements the functions, types, and interfaces for the module.
Package settings provides utility functions for coalescing values of various types.
Package settings implements the functions, types, and interfaces for the module.
Package settings implements the functions, types, and interfaces for the module.
Package settings implements the functions, types, and interfaces for the module.
Index ¶
- func Apply[S any, F FuncType[S]](target *S, settings []F) *S
- func ApplyAny[S any](target *S, settings []any) *S
- func ApplyBuilder[S any](target *S, builder Builder[S]) *S
- func ApplyDefault[S any, F FuncType[S]](s S, settings []F) *S
- func ApplyDefaultE[S any](target S, settings []FuncE[S]) (*S, error)
- func ApplyDefaults[S any](s *S, fs []func(*S)) *S
- func ApplyDefaultsOr[S any](s *S, fs ...func(*S)) *S
- func ApplyDefaultsOrError[S any](s *S, fs ...func(*S)) (*S, error)
- func ApplyDefaultsOrZero[S any](fs ...func(*S)) *S
- func ApplyE[S any, Func FuncEType[S]](target *S, settings []Func) (*S, error)
- func ApplyErrorDefaults[S any](s *S, fs []func(*S)) (*S, error)
- func ApplyErrorDefaultsOr[S any](s *S, fs ...func(*S)) (*S, error)
- func ApplyErrorDefaultsOrZero[S any](fs ...func(*S)) (*S, error)
- func ApplyMixed[S any](target *S, settings []any) (*S, error)
- func ApplyOr[S any](s *S, fs ...func(*S)) *S
- func ApplyOrZero[S any](fs ...func(*S)) *S
- func ApplyStrict[S any](target *S, settings []any) *S
- func ApplyStrictE[S any](target *S, settings []any) (*S, error)
- func ApplyWith[S any, F FuncType[S]](target *S, settings ...F) *S
- func ApplyWithDefault[S any, F FuncType[S]](s S, settings ...F) *S
- func ApplyWithDefaultE[S any](target S, settings ...FuncE[S]) (*S, error)
- func ApplyWithE[S any, Func FuncEType[S]](target *S, settings ...Func) (*S, error)
- func ApplyWithZero[S any, F FuncType[S]](settings ...F) *S
- func ApplyWithZeroE[S any](settings ...FuncE[S]) (*S, error)
- func ApplyZero[S any, F FuncType[S]](settings []F) *S
- func ApplyZeroE[S any](settings []FuncE[S]) (*S, error)
- func Coalesce[T comparable](a, b T) T
- func CoalesceBool[T types.Boolean](a, b T) T
- func CoalesceFloat[T types.Float](a, b T) T
- func CoalesceInt[T types.Integer](a, b T) T
- func CoalesceString[T types.String](a, b T) T
- func IsConfigError(err error) bool
- func IsEmptyTargetValueError(err error) bool
- func IsExecutionFailedError(err error) bool
- func IsUnsupportedTypeError(err error) bool
- func New[S any, F FuncType[S]](settings []F) *S
- func WithDefault[S any](target S, settings ...any) *S
- func WithDefaultE[S any](target *S, settings ...any) (*S, error)
- func WithInterfaces[S any](target *S, settings ...any) (*S, error)
- func WithMixed[S any](target *S, settings ...any) (*S, error)
- func WithMixedZero[S any](settings ...any) (*S, error)
- func WithZero[S any](settings ...any) *S
- func WithZeroE[S any](settings ...any) (*S, error)
- type Applier
- type ApplierE
- type ApplyFunc
- type ApplySetting
- type Builder
- type ConfigError
- type Defaulter
- type ErrorCode
- type ErrorDefaulter
- type Func
- type FuncE
- type FuncEType
- type FuncType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply configures a target struct with ordered settings. Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyAny ¶
ApplyAny applies a list of settings to a target struct. Deprecated: Use ApplyMixed with slice syntax. Will be removed in v0.3.0
Before: ApplyAny(&obj, []interface{}{f1, f2})
After: ApplyMixed(&obj, []interface{}{f1, f2}) (*obj, error)
func ApplyBuilder ¶ added in v0.3.0
ApplyBuilder applies settings from a builder
func ApplyDefault ¶ added in v0.2.2
ApplyDefault applies a list of settings to a target struct. Parameters:
- s: Struct to be configured
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyDefaultE ¶ added in v0.2.2
ApplyDefaultE is an apply settings with Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
- error: Any error encountered during configuration
func ApplyDefaults ¶ added in v0.1.2
func ApplyDefaults[S any](s *S, fs []func(*S)) *S
ApplyDefaults applies the given settings and default settings to the provided value. Decrypted: use Apply instead of ApplyDefaults
It first applies the given settings using the Apply function, then checks if the value implements the Defaulter interface. If it does, it calls the ApplyDefaults method to apply the default settings.
func ApplyDefaultsOr ¶ added in v0.1.2
func ApplyDefaultsOr[S any](s *S, fs ...func(*S)) *S
ApplyDefaultsOr applies the given settings and default settings to the provided value. Decrypted: use WithZeroE instead of ApplyDefaultsOr
It is a convenience wrapper around ApplyDefaults that accepts a variable number of setting functions.
func ApplyDefaultsOrError ¶ added in v0.1.3
ApplyDefaultsOrError applies the given settings and default settings to the provided value. Decrypted: use WithDefaultE instead of ApplyDefaultsOrError
It is a convenience wrapper around ApplyDefaults that accepts a variable number of setting functions.
func ApplyDefaultsOrZero ¶ added in v0.1.2
func ApplyDefaultsOrZero[S any](fs ...func(*S)) *S
ApplyDefaultsOrZero applies the given settings and default settings to a zero value of the type. Decrypted: use WithZero instead of ApplyDefaultsOrZero
It creates a zero value of the type, then calls ApplyDefaults to apply the given settings and default settings.
func ApplyE ¶ added in v0.2.0
ApplyE applies a list of settings to a target struct. Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
- error: Any error encountered during configuration
func ApplyErrorDefaults ¶ added in v0.1.3
ApplyErrorDefaults applies the given settings and default settings to the provided value. Decrypted: use WithDefaultE instead of ApplyErrorDefaults
It first applies the given settings using the Apply function, then checks if the value implements the ErrorDefaulter interface. If it does, it calls the ApplyDefaults method
func ApplyErrorDefaultsOr ¶ added in v0.1.3
ApplyErrorDefaultsOr applies the given settings and default settings to the provided value. Decrypted: use WithDefaultE instead of ApplyErrorDefaultsOr
It is a convenience wrapper around ApplyDefaults that accepts a variable number of interface{} values.
func ApplyErrorDefaultsOrZero ¶ added in v0.1.3
ApplyErrorDefaultsOrZero applies the given settings and default settings to a zero value of the type. Decrypted: use WithZeroE instead of ApplyErrorDefaultsOrZero
It creates a zero value of the type, then calls ApplyDefaults to apply the given settings and default settings.
func ApplyMixed ¶ added in v0.2.0
ApplyMixed applies a list of settings to a target struct. Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyOr ¶
func ApplyOr[S any](s *S, fs ...func(*S)) *S
ApplyOr is an apply settings with defaults Decrypted: use WithDefault instead of ApplyOr. Will be removed in v0.3.0
func ApplyOrZero ¶
func ApplyOrZero[S any](fs ...func(*S)) *S
ApplyOrZero is an apply settings with defaults Decrypted: use WithZero instead of ApplyOrZero. Will be removed in v0.3.0
func ApplyStrict ¶ added in v0.2.0
ApplyStrict is a version for strict type safety Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
Panics:
- If target is nil
- If any setting is not a supported type
func ApplyStrictE ¶ added in v0.2.0
ApplyStrictE applies a list of settings to a target struct. Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyWith ¶ added in v0.2.2
ApplyWith applies a list of settings to a target struct. Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyWithDefault ¶ added in v0.2.2
ApplyWithDefault applies a list of settings to a target struct. Parameters:
- s: Struct to be configured
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyWithDefaultE ¶ added in v0.2.2
ApplyWithDefaultE is an apply settings with defaults Parameters:// Parameters:
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyWithE ¶ added in v0.2.2
ApplyWithE applies a list of settings to a target struct. Parameters:
- target: Pointer to the struct being configured (non-nil)
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
- error: Any error encountered during configuration
func ApplyWithZero ¶ added in v0.2.2
ApplyWithZero applies a list of settings to a target struct. Parameters:
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyWithZeroE ¶ added in v0.2.2
ApplyWithZeroE is an apply settings with defaults Parameters:
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyZero ¶ added in v0.2.2
ApplyZero applies a list of settings to a target struct. Parameters:
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func ApplyZeroE ¶ added in v0.2.2
ApplyZeroE is an apply settings with defaults Parameters:
- settings: Ordered list of configuration functions
Returns:
- *S: Configured struct pointer (same as input)
func Coalesce ¶ added in v0.2.5
func Coalesce[T comparable](a, b T) T
Coalesce returns the first non-zero value of comparable type T If a is non-zero, returns a; otherwise returns b
func CoalesceBool ¶ added in v0.2.5
CoalesceBool provides type-safe coalescing for boolean types Returns the first non-zero boolean value
func CoalesceFloat ¶ added in v0.2.5
CoalesceFloat handles floating point coalescing with epsilon comparison Returns b if a is NaN or its absolute value is below epsilon threshold
func CoalesceInt ¶ added in v0.2.5
CoalesceInt provides type-safe coalescing for integer types Returns the first non-zero integer value
func CoalesceString ¶ added in v0.2.5
CoalesceString handles string coalescing with type safety Converts parameters to string type before comparison
func IsConfigError ¶ added in v0.2.0
IsConfigError checks if the given error is a *ConfigError instance. Parameters:
- err: error to be checked
Returns:
- true if err is *ConfigError type, false otherwise
func IsEmptyTargetValueError ¶ added in v0.2.0
func IsExecutionFailedError ¶ added in v0.2.0
func IsUnsupportedTypeError ¶ added in v0.2.0
func New ¶ added in v0.2.0
New creates a zero-value instance and applies settings. Parameters:
- settings: Configuration functions to apply
Retur Returns:
- *S: New configured instance
func WithDefault ¶ added in v0.2.0
WithDefault applies settings and handles default values. Parameters:
- target: Struct pointer to configure
- settings: Configuration functions to apply
Returns:
- *S: Configured struct pointer
func WithDefaultE ¶ added in v0.2.0
WithDefaultE applies settings and handles default values. Parameters:
- target: Struct pointer to configure
- settings: Configuration functions to apply
Returns:
- *S: Configured struct pointer
- error: Error if any occurred during the configuration process
func WithInterfaces ¶ added in v0.3.0
func WithMixed ¶ added in v0.2.0
WithMixed applies settings and handles default values. Parameters:
- target: Struct pointer to configure
- settings: Configuration functions to apply
Returns:
- *S: Configured struct pointer
- error: Error if any occurred during the configuration process
func WithMixedZero ¶ added in v0.2.0
WithMixedZero applies settings and handles default values. Parameters:
- settings: Configuration functions to apply
Returns:
- *S: Configured struct pointer
- error: Error if any occurred during the configuration process
Types ¶
type Applier ¶ added in v0.2.0
type Applier[S any] interface { // Apply modifies the target struct with specific settings Apply(target *S) }
Applier defines the interface for configuration application mechanisms.
type ApplierE ¶ added in v0.2.0
ApplierE defines enhanced configuration interface with error handling
type ApplyFunc ¶
type ApplyFunc[S any] func(*S)
ApplyFunc is a ApplyFunc function for Apply Decrypted: use Func instead of ApplyFunc. Will be removed in v0.3.0
type ApplySetting ¶
type ApplySetting[S any] interface { Apply(v *S) }
ApplySetting defines the interface for configuration settings. Decrypted: use Applier instead of ApplySetting. Will be removed in v0.3.0
type Builder ¶ added in v0.3.0
type Builder[S any] interface { Add(setting Func[S]) Builder[S] AddWhen(condition bool, setting Func[S]) Builder[S] Build() []Func[S] }
Builder defines the interface for building configuration settings
func NewBuilder ¶ added in v0.3.0
NewBuilder creates a new configuration builder
type ConfigError ¶ added in v0.2.0
type ConfigError struct {
Code ErrorCode // Error category
TypeString string // Setting type info
Err error // Original error
}
func (*ConfigError) Error ¶ added in v0.2.0
func (e *ConfigError) Error() string
Error message display is enhanced
func (*ConfigError) Unwrap ¶ added in v0.2.0
func (e *ConfigError) Unwrap() error
type Defaulter ¶ added in v0.1.2
type Defaulter interface {
// Defaults applies the default settings to the implementing type.
Defaults()
}
Defaulter is an interface that provides a method to apply default settings. Decrypted: use Apply instead of Defaulter
type ErrorDefaulter ¶ added in v0.1.3
type ErrorDefaulter interface {
// Defaults applies the default settings to the implementing type and returns an error.
Defaults() error
}
ErrorDefaulter is an interface that provides a method to apply default settings and return an error. Decrypted: use ApplyE instead of ErrorDefaulter
type Func ¶ added in v0.2.0
type Func[S any] func(*S)
Func defines the standard function type for configuration operations.
func FromEnv ¶ added in v0.3.0
FromEnv creates a configuration function that reads from environment variables
type FuncE ¶ added in v0.2.0
FuncE defines enhanced configuration function with error return