Documentation
¶
Overview ¶
Package config provides hierarchical application configuration loading, profile merging, overrides, type conversion, unmarshaling, and validation for Rays.
Index ¶
- func Convert(value any, t reflect.Type) (reflect.Value, Error)
- func ConvertNumeric[T2, T1 IntegerConstraint | FloatConstraint](value T1) T2
- func ConvertNumericString[T IntegerConstraint | FloatConstraint](value T) string
- func ConvertStringNumeric[T IntegerConstraint | FloatConstraint](value string) (T, Error)
- func Validate(obj any) Error
- type Config
- func (this *Config) ActiveProfiles() []string
- func (this *Config) AddConfigFS(fsys fs.FS) Error
- func (this *Config) AddDefaultConfigFS(fsys fs.FS) Error
- func (this *Config) AddOverride(key, value string) Error
- func (this *Config) Clear()
- func (this *Config) CopyDefaultConfig(from, to string) Error
- func (this *Config) CopyDefaultConfigForProfile(from, to, profile string) Error
- func (this *Config) GetConfigValue(key string) (string, Error)
- func (this *Config) GetSubConfig(key string) (*Config, Error)
- func (this *Config) InitConfig() Error
- func (this *Config) LoadConfig(config map[string]any) Error
- func (this *Config) LoadConfigAt(config map[string]any, root string) Error
- func (this *Config) LoadConfigForProfile(config map[string]any, profile string) Error
- func (this *Config) LoadConfigForProfileAt(config map[string]any, profile, root string) Error
- func (this *Config) LoadDefaultConfig(config map[string]any) Error
- func (this *Config) LoadDefaultConfigAt(config map[string]any, root string) Error
- func (this *Config) Reset()
- func (this *Config) SetActiveProfiles(profiles []string) Error
- func (this *Config) SetLogger(l *logger.Logger)
- func (this *Config) Unmarshal(obj any) Error
- type InvalidTypeKeyError
- type KeyNotFoundError
- type YamlConfigFSLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert converts a source value of any type into a reflect.Value matching target type t. It supports direct assignment, time.Duration strings, []byte, encoding.TextUnmarshaler, boolean conversions, and numeric string parsing and formatting.
func ConvertNumeric ¶
func ConvertNumeric[T2, T1 IntegerConstraint | FloatConstraint](value T1) T2
ConvertNumeric casts a numeric value of type T1 directly to numeric type T2.
func ConvertNumericString ¶
func ConvertNumericString[T IntegerConstraint | FloatConstraint](value T) string
ConvertNumericString converts an integer or float value of type T into its string representation.
func ConvertStringNumeric ¶
func ConvertStringNumeric[T IntegerConstraint | FloatConstraint](value string) (T, Error)
ConvertStringNumeric parses a numeric string into target integer or float type T.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config manages hierarchical configuration data, profiles, defaults, overrides, and unmarshaling into strongly-typed structures.
func NewConfig ¶
func NewConfig() *Config
NewConfig initializes and returns an empty Config container with a default logger.
func NewConfigFor ¶
NewConfigFor constructs and returns a new Config preloaded with the given configuration map.
func (*Config) ActiveProfiles ¶
ActiveProfiles returns the slice of active configuration profile names.
func (*Config) AddConfigFS ¶
AddConfigFS registers a filesystem to load configuration files from during initialization. Returns an error if the container has already been initialized.
func (*Config) AddDefaultConfigFS ¶
AddDefaultConfigFS registers a filesystem providing default fallback configuration files. Returns an error if the container has already been initialized.
func (*Config) AddOverride ¶
AddOverride registers a key-value override that takes precedence over loaded configuration values. Returns an error if the container has already been initialized.
func (*Config) Clear ¶
func (this *Config) Clear()
Clear clears the cached merged configuration results and resets the initialization state, allowing the configuration container to be re-initialized.
func (*Config) CopyDefaultConfig ¶
CopyDefaultConfig registers a duplication rule copying default configuration from one path to another. Returns an error if the container has already been initialized.
func (*Config) CopyDefaultConfigForProfile ¶
CopyDefaultConfigForProfile registers a duplication rule copying default configuration for a specific profile. Returns an error if the container has already been initialized.
func (*Config) GetConfigValue ¶
GetConfigValue retrieves a string configuration value by dot-notated key path, applying registered overrides and converting the value to string.
func (*Config) GetSubConfig ¶
GetSubConfig extracts and returns an isolated sub-configuration rooted at the specified dot-separated key path, deep-cloning backing maps and propagating matching prefix overrides.
func (*Config) InitConfig ¶
func (this *Config) InitConfig() Error
InitConfig executes configuration initialization: 1. Invokes all discovered ConfigurationParser instances on default and application filesystems. 2. Merges default configurations, copies duplicated subtrees, and merges base configs. 3. Merges active profile configurations into the final result map.
Returns an error if the container has already been initialized.
func (*Config) LoadConfig ¶
LoadConfig merges application configuration values into the container. Returns an error if the container has already been initialized.
func (*Config) LoadConfigAt ¶
LoadConfigAt merges configuration values nested under a dot-delimited root key path. Returns an error if the container has already been initialized.
func (*Config) LoadConfigForProfile ¶
LoadConfigForProfile merges configuration values for a specific profile into the container. Returns an error if the container has already been initialized.
func (*Config) LoadConfigForProfileAt ¶
LoadConfigForProfileAt merges configuration values for a profile nested under a dot-delimited root key path. Returns an error if the container has already been initialized.
func (*Config) LoadDefaultConfig ¶
LoadDefaultConfig merges default fallback configuration values into the container. Returns an error if the container has already been initialized.
func (*Config) LoadDefaultConfigAt ¶
LoadDefaultConfigAt merges default configuration values nested under a dot-delimited root key path. Returns an error if the container has already been initialized.
func (*Config) Reset ¶
func (this *Config) Reset()
Reset clears all configurations, profiles, overrides, registered filesystems, and cached state.
func (*Config) SetActiveProfiles ¶
SetActiveProfiles configures the list of active profile names to activate during initialization. Returns an error if the container has already been initialized.
type InvalidTypeKeyError ¶
type InvalidTypeKeyError struct {
*DefaultError
}
InvalidTypeKeyError represents an error when traversing a key path encounters an incompatible data type.
func NewInvalidTypeKeyError ¶
func NewInvalidTypeKeyError(key, component string) *InvalidTypeKeyError
NewInvalidTypeKeyError constructs an InvalidTypeKeyError for the given key and incompatible path component.
type KeyNotFoundError ¶
type KeyNotFoundError struct {
*DefaultError
}
KeyNotFoundError represents an error when a requested configuration key path does not exist.
func NewKeyNotFoundError ¶
func NewKeyNotFoundError(key, component string) *KeyNotFoundError
NewKeyNotFoundError constructs a KeyNotFoundError for the given key and failing path component.
type YamlConfigFSLoader ¶
type YamlConfigFSLoader struct{}
YamlConfigFSLoader implements core.ConfigurationParser for YAML files located in an fs.FS.
func (*YamlConfigFSLoader) ParseConfigurationFilesystem ¶
func (this *YamlConfigFSLoader) ParseConfigurationFilesystem(fsys fs.FS, loader func(m map[string]any, profile string)) Error
ParseConfigurationFilesystem walks fsys, unmarshaling any matching YAML configuration files and invoking loader with the parsed map and extracted profile name. Returns an error if filesystem walking, file reading, or YAML unmarshaling fails.