- We can use different ways to configure an app: local/global variables, flags, environment variables, config files.
- Solutions like viper exist for go apps to combine those solutions all together.
- Should we use environment variables for app configuration?
In my opinion, all the OS-dependent configuration options should be passed explicitly at the start of the application. Flags are the perfect way for that, because on the contrary of env variables, it's os-independent and explicit.
Here are all the reasons why we shouldn't use environment variables:
Dynamically set
: they can be set by other users, so we are not really sure of their value across the time.OS-dependent
: risks of collision, for example if a variable X has a special meaning in one OS.Implicit dependencies
: env variables are a form of dependency for our app, and experience has shown that dependencies should always be explicit.
-> Best practices:
- strictYAML proposes a simplified implementation of YAML spec.
- "If a necessary feature has a high astonishment factor, it may be necessary to redesign the feature." (wiki)
- semver is a good practice to follow when releasing public faced software.