-
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
config file can't be optional #1
Comments
Agree. Please Send me a pull request. Steve Francia
|
Closed in favor of #2 |
So it is really not possible to have Viper not error when the config file does not exist? |
I have the same question... @spf13 @joshuarubin? |
Leaving the solution here for future reference: err := viper.ReadInConfig()
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
panic(err)
} Basically you just have to check the error and ignore it if it is a config not found error. |
if err := config.ReadConfig(strings.NewReader("")); err != nil {
log.Fatal(err)
} |
Hm, calling |
Oh, yeah, you are right. |
It would be more useful if ReadInConfig could return an error instead of causing the process to Exit if the config can't be found. This would enable the case where the whole file can be optional and the values read from defaults.
The text was updated successfully, but these errors were encountered: