Skip to content

Conversation

umurgdk
Copy link

@umurgdk umurgdk commented Feb 19, 2018

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 using mapstructure library to
unmarshall structs from maps. This is why yaml struct tags converted to
mapstructure ones.


This change is Reviewable

This commit also makes possible to use json files as configuration
files via `viper` configuration library. And contains breaking changes
to configuration.

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.
@umurgdk
Copy link
Author

umurgdk commented Feb 19, 2018

I will update the readme and example config files after the code review.

@techknowlogick
Copy link
Collaborator

Thanks for this PR :)

The codebase has evolved since this PR was made, and so I will close it. If you are open to re-submitting it and resolving the conflicts, I think it would be a benefit to the project.

@ewassef
Copy link

ewassef commented Apr 25, 2022

I would like to reopen this.. i have updated the PR @umurgdk @techknowlogick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants