diff --git a/.gitignore b/.gitignore index 62de1d0..edc6ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /.idea/ /demo-app /dist -/resource_app.toml +/resource_app*.toml /sessions /static /ui/css/ diff --git a/changelog.md b/changelog.md index 0d632d6..e67978f 100644 --- a/changelog.md +++ b/changelog.md @@ -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). ## 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 - fix logged application name diff --git a/internal/services/configuration.go b/internal/services/configuration.go index 5496118..db40021 100644 --- a/internal/services/configuration.go +++ b/internal/services/configuration.go @@ -32,7 +32,10 @@ import ( "github.com/spf13/pflag" ) -const defaultServerPort = 4000 +const ( + defaultServerPort = 4000 + defaultFile = "resource_app.toml" +) var DefaultConfiguration = map[string]interface{}{ "server.bind_address": "", @@ -74,6 +77,10 @@ func ConfigureApplication( _ = 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") for _, c := range cFiles { 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") } - 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)) if err = config.Load(env.Provider(prefix, ".", func(s string) string {