Add env variable support for configuration #225
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit also makes possible to use json files as configuration
files via
viper
configuration library.This PR contains breaking changes on configuration to make
configuration overridable by the environment variables. To make it
support nested struct overrides struct tags are renamed to not
contain any underscore in their names. This is going to break old
configuration files.
Because of viper's limitations of detecting new map keys from env
variables, a little procedure goes trough prefixed env variables and
override viper settings by the parsed value of them. If the
configuration file is in yaml format env variables can contain correct
yaml strings and they will be parsed correctly. This behaviour is same
for json files too.
PS: viper doesn't use file format parsers for unmarshalling the structures.
It parses files as
interface{}
and the usingmapstructure
library tounmarshall structs from maps. This is why
yaml
struct tags converted tomapstructure
ones.This change is