Configuration
Configuration
Load, resolve, and bind application configuration in Procyon.
Configuration
The config package gives Procyon applications a structured way to work with
runtime settings. It collects property sources, resolves values by name, and
binds configuration into Go structs when the application needs typed options.
Property sources
Property sources keep configuration values together with a source name and
origin. Add sources to PropertySources in the order you want them to be
resolved.
sources := config.NewPropertySources()
sources.PushBack(config.NewMapPropertySource("application", map[string]any{
"server.port": 8080,
}))YAML loading
Use YamlPropertySourceLoader to load .yaml or .yml resources into a
property source.
loader := config.NewYamlPropertySourceLoader()
source, err := loader.Load(ctx, "application", resource)
if err != nil {
return err
}
sources.PushBack(source)Binding properties
The default binder maps scalar values, slices, maps, and structs into a target value.
type ServerProperties struct {
Port int `property:"port"`
}
var server ServerProperties
binder := config.NewDefaultPropertyBinder(sources)
if err := binder.Bind("server", &server); err != nil {
return err
}