Documentation
¶
Overview ¶
Package config provides a unified configuration loader for OpenChoreo components.
Index ¶
- type Loader
- func (l *Loader) LoadFlags(flags *pflag.FlagSet, mappings map[string]string) error
- func (l *Loader) LoadWithDefaults(defaults any, configPath string) error
- func (l *Loader) Raw() map[string]any
- func (l *Loader) Set(key string, value any) error
- func (l *Loader) Unmarshal(path string, out any) error
- func (l *Loader) UnmarshalAndValidate(path string, out any) error
- type Option
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles configuration loading from multiple sources.
func NewLoader ¶
NewLoader creates a new configuration loader. envPrefix should be like "OC_API" (without trailing delimiter). Environment variables use double underscore (__) for nesting: OC_API__SERVER__PORT -> server.port
func (*Loader) LoadFlags ¶
LoadFlags applies CLI flag overrides using explicit mappings. Only flags that were explicitly set by the user are applied. Call this after LoadWithDefaults for highest priority overrides.
func (*Loader) LoadWithDefaults ¶
LoadWithDefaults loads configuration with the following priority (highest to lowest):
- Environment variables (OC_API__SERVER__PORT -> server.port)
- Config file (YAML)
- Struct defaults
If configPath is specified but the file does not exist, an error is returned. If configPath is empty, only defaults and environment variables are used.
func (*Loader) Raw ¶
Raw returns all loaded configuration as a nested map. Useful for config dumping (e.g., --dump-config).
type Option ¶
type Option func(*Loader)
Option configures a Loader.
func WithLogger ¶
WithLogger sets a custom logger for debug output.