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 implements the functions, types, and interfaces for the module.
Package settings implements the functions, types, and interfaces for the module.
Index ¶
- Constants
- func Apply[S any](target *S, settings []func(*S)) *S
- func ApplyAny[S any](target *S, settings []any) *S
- 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](target *S, settings []func(target *S) error) (*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 IsConfigError(err error) bool
- func IsEmptyTargetValueError(err error) bool
- func IsExecutionFailedError(err error) bool
- func IsUnsupportedTypeError(err error) bool
- func New[S any](settings []func(*S)) *S
- func WithDefault[S any](target *S, settings ...any) *S
- func WithDefaultE[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 ConfigError
- type Defaulter
- type ErrorDefaulter
- type Func
- type FuncE
- type Result
- func NewErrorResult[S any](err error) Result[S]
- func NewResult[S any](val *S, err error) Result[S]
- func NewValueResult[S any](val *S) Result[S]
- func ResultMixed[S any](target *S, settings []any) Result[S]
- func ResultWith[S any](target *S, settings []func(*S)) Result[S]
- func ResultWithE[S any](target *S, settings []func(*S) error) Result[S]
- func ResultWithZero[S any](settings []func(*S)) Result[S]
- func ResultWithZeroE[S any](settings []func(*S) error) Result[S]
- func ResultZeroMixed[S any](settings []any) Result[S]
- type Setting
Constants ¶
const ( ErrUnsupportedType = iota ErrExecutionFailed ErrEmptyTargetValue )
Error types for configuration errors
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply[S any](target *S, settings []func(*S)) *S
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 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 IsConfigError ¶ added in v0.2.0
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
func New[S any](settings []func(*S)) *S
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 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 ConfigError ¶ added in v0.2.0
type ConfigError struct {
Type int // 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 {
// ApplyDefaults applies the default settings to the implementing type.
ApplyDefaults()
}
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 {
// ApplyDefaults applies the default settings to the implementing type and returns an error.
ApplyDefaults() 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.
type Result ¶ added in v0.2.0
type Result[S any] interface { // Value returns the configured struct pointer Value() *S // Err returns any error occurred during configuration Err() error // Unwrap returns both value and error for direct handling Unwrap() (*S, error) // MustUnwrap panics if error exists MustUnwrap() *S }
Result defines the unified return type for configuration operations
func NewErrorResult ¶ added in v0.2.0
func NewValueResult ¶ added in v0.2.0
func ResultMixed ¶ added in v0.2.0
func ResultWith ¶ added in v0.2.0
func ResultWithE ¶ added in v0.2.0
func ResultWithZero ¶ added in v0.2.0
ResultWithZero creates a zero-value instance and applies settings. Parameters:
- settings: Configuration functions to apply
Returns:
- *S: New configured instance