Re-order configuration precedence

This commit is contained in:
Jan Dittberner 2023-07-29 21:06:26 +02:00
parent 4a50b42067
commit f35a59e59c
3 changed files with 14 additions and 9 deletions

2
.gitignore vendored
View file

@ -2,7 +2,7 @@
/.idea/ /.idea/
/demo-app /demo-app
/dist /dist
/resource_app.toml /resource_app*.toml
/sessions /sessions
/static /static
/ui/css/ /ui/css/

View file

@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased ## Unreleased
### Changed
- re-order configuration precedence
1. default config file idp.toml
2. config files given via the `--conf` command line argument
3. environment variables with the `RESOURCE_APP_` prefix
### Fixed ### Fixed
- fix logged application name - fix logged application name

View file

@ -32,7 +32,10 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
const defaultServerPort = 4000 const (
defaultServerPort = 4000
defaultFile = "resource_app.toml"
)
var DefaultConfiguration = map[string]interface{}{ var DefaultConfiguration = map[string]interface{}{
"server.bind_address": "", "server.bind_address": "",
@ -74,6 +77,10 @@ func ConfigureApplication(
_ = config.Load(confmap.Provider(defaultConfig, "."), nil) _ = config.Load(confmap.Provider(defaultConfig, "."), nil)
if err = config.Load(file.Provider(defaultFile), toml.Parser()); err != nil && !os.IsNotExist(err) {
logrus.WithError(err).WithField("file", defaultFile).Fatal("error loading configuration from file")
}
cFiles, _ := f.GetStringSlice("conf") cFiles, _ := f.GetStringSlice("conf")
for _, c := range cFiles { for _, c := range cFiles {
if err = config.Load(file.Provider(c), toml.Parser()); err != nil { if err = config.Load(file.Provider(c), toml.Parser()); err != nil {
@ -85,13 +92,6 @@ func ConfigureApplication(
logger.WithError(err).Fatal("error loading configuration from command line") logger.WithError(err).Fatal("error loading configuration from command line")
} }
if err = config.Load(
file.Provider("resource_app.toml"),
toml.Parser(),
); err != nil && !os.IsNotExist(err) {
logrus.WithError(err).Fatal("error loading configuration from resource_app.toml")
}
prefix := fmt.Sprintf("%s_", strings.ToUpper(appName)) prefix := fmt.Sprintf("%s_", strings.ToUpper(appName))
if err = config.Load(env.Provider(prefix, ".", func(s string) string { if err = config.Load(env.Provider(prefix, ".", func(s string) string {