Configuration Files
Load application settings from Procyon's default resources location.
Procyon looks for configuration in the resources/ directory. The default file
name is procyon, so a typical application starts with resources/procyon.yml
or resources/procyon.yaml.
Use this file for settings that belong to the application: server ports, integration endpoints, feature flags, timeouts, and package-specific options.
server:
port: 8080
readTimeout: 5
database:
host: localhost
port: 5432
username: app
password: secretHow files are loaded
Procyon registers the YAML property source loader during startup. The loader
supports both yaml and yml extensions and turns nested YAML into
dot-separated property names.
loader := config.NewYamlPropertySourceLoader()
source, err := loader.Load(ctx, "resources/procyon.yml", resource)
if err != nil {
return err
}
sources.PushBack(source)Most applications do not need to call the loader directly. The application runtime uses registered loaders when it prepares the environment.
Nested keys
Nested YAML maps are flattened before values are resolved or bound:
mail:
host: smtp.example.com
port: 587
tls: trueThese values become:
mail.host=smtp.example.com
mail.port=587
mail.tls=trueThis is why the same mail prefix can be used with the binder later.
Custom file formats
You can support another file format by registering a component that implements
config.PropertySourceLoader. The loader declares the extensions it supports
and returns a PropertySource for the resolved resource.
type JsonPropertySourceLoader struct{}
func NewJsonPropertySourceLoader() *JsonPropertySourceLoader {
return &JsonPropertySourceLoader{}
}
func (l *JsonPropertySourceLoader) Extensions() []string {
return []string{"json"}
}
func (l *JsonPropertySourceLoader) Load(
ctx context.Context,
name string,
resource io.Resource,
) (config.PropertySource, error) {
reader, err := resource.Reader()
if err != nil {
return nil, err
}
values := map[string]any{}
if err := json.NewDecoder(reader).Decode(&values); err != nil {
return nil, err
}
return config.NewMapPropertySource(name, values), nil
}Register the loader like any other component:
func init() {
component.Register(NewJsonPropertySourceLoader)
}After registration, the standard data loader can use resources/procyon.json
in the same configuration flow.
