-
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
Should find config file which with extension first. #844
Comments
I'm running into a similar issue.
And then call I propose that the following suggestion
The current implementation is
|
I noticed this issue today as well, but don't really like the proposed solution. Some users may not have their config file be the same as the binary, in which case it's completely reasonable to want/expect a config file without an extension in the CWD/bindir to override some system config. Another way to do this is to ignore executable files. There isn't a great way to do this in Windows, but on that system the binary generally has the func exists(fs afero.Fs, path string) (bool, error) {
stat, err := fs.Stat(path)
if err == nil {
- return !stat.IsDir(), nil
+ if stat.IsDir() {
+ return false, nil
+ }
+ if stat.Mode().Perm()&0111 != 0 {
+ return false, nil
+ }
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
} |
another way would be to compare it against the path of the application's binary |
Thanks @SmallTianTian for writing this report. I also had issues with the way Viper tries to find a suitable config file to load.
I think this is something important to keep in mind. IMO it would be best to have explicit control over this. As Viper v1 is currently built (I haven't looked at v2 yet), the
It is this multi-purpose nature of the setting that makes it confusing for me. When writing the configuration, I need to set the config type. But when trying to read it, I have to clear it again, otherwise Viper tries to load the (extensionless) executable as if it were configuration. On top of this, there is the confusion stemming from the file-finding implementation, which doesn't prioritise the set configuration type. I had really weird issues when I first used JSON and then switched to YAML, only to find that Viper would still try and load the JSON file first. IMO Viper should look at the configured file type before anything else. My proposal is thus two-fold:
|
When it's a
go
file, it can readmain.yaml
for config file. But when you build this go file(main
), you will find the executable file will be reading first. I'm set config type and config name, but I couldn't get this file.I've read #818, extension-less filename is neeeded. So, I think the extension config file should be high weight.
The text was updated successfully, but these errors were encountered: