Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viperx: Added viper BindEnvsToSchema helper #85

Merged
merged 4 commits into from
Oct 26, 2019
Merged

Conversation

aeneasr
Copy link
Member

@aeneasr aeneasr commented Oct 26, 2019

if err != nil {
return err
}
return viper.BindEnv(keys...)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I noted previously this usage of BindEnv is incorrect: this function does not accept multiple keys https://github.com/spf13/viper/blob/master/viper.go#L960 It either accepts one parameter (the key) or two parameters (the key and the corresponding ENV_VAR_NAME)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how do we deal with the env names? I guess with the effect of SetEnvKeyReplacer it will work automatically, so afterviper.BindEnv("foo.bar.baz") env FOO_BAR_BAZ should work, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks, I overlooked that completely. Fixed and added a test to make sure this works properly.

Also, how do we deal with the env names? I guess with the effect of SetEnvKeyReplacer it will work automatically, so afterviper.BindEnv("foo.bar.baz") env FOO_BAR_BAZ should work, right?

Exactly!

@aeneasr aeneasr merged commit 329ff71 into master Oct 26, 2019
@aeneasr aeneasr deleted the env-from-schema branch October 26, 2019 20:38
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.

2 participants