-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Default values doesn't work (SetDefault function) #158
Comments
If I'm doing something wrong, please correct my example. Thanks in advance |
I think this is a duplicate of #71. A workaround can be found in that ticket: #71 (comment). |
Thanks for response, but after changing the line
with
It still doesn't work. The output is the same |
@vlkv Do you find a way to make it work finally? I made it like that: if c.Get("params.p3") == nil {
c.Set("params.p3", "333")
} |
c.Set("params.p3", "333") <<<<< I'd like to do this BEFORE load actual values from file. If I would do this AFTER - then defaults lose their sense, becase I would do this every time in every place after load. So, I've created my own config module https://github.com/vlkv/ya-go-config It's not as powerfull as viper, it's tiny little simple. But I don't need more. |
@vlkv I'm reading the conf file before the If It's behaviour of default value isn't it? |
#158 (comment) Here is what I've expected |
Fixes #71, #93, #158, #168, #209, #141, #160, #162, #190 * Fixed: indentation in comment * Fixed: Get() returns nil when nested element not found * Fixed: insensitiviseMaps() made recursive so that nested keys are lowercased * Fixed: order of expected<=>actual in assert.Equal() statements * Fixed: find() looks into "overrides" first * Fixed: TestBindPFlags() to use a new Viper instance * Fixed: removed extra aliases from display in Debug() * Added: test for checking precedence of dot-containing keys. * Fixed: Set() and SetDefault() insert nested values * Added: tests for overriding nested values * Changed: AllKeys() includes all keys / AllSettings() includes overridden nested values * Added: test for shadowed nested key * Fixed: properties parsing generates nested maps * Fixed: Get() and IsSet() work correctly on nested values * Changed: modifier README.md to reflect changes
Fixed by PR #195 |
func getEnvValue(key string, defaultValue string) string { |
This surely works. |
Hi! I'm trying to use default values for my configuration params. They seem to be NOT working. Here is the example:
And the config.json is
The text was updated successfully, but these errors were encountered: