Update viper_go1_15.go

If i have two config file in the same path, one's type is yaml and another is toml. But i set the type: `viper.SetConfigType("yaml")`, old viper_go1_15.go will return me the toml's config. Now the bug is fixed.
This commit is contained in:
XYZ0901 2022-03-07 01:29:12 +08:00 committed by GitHub
parent 343434eb50
commit ff657bbec2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,13 @@ func (v *Viper) findConfigFile() (string, error) {
func (v *Viper) searchInPath(in string) (filename string) { func (v *Viper) searchInPath(in string) (filename string) {
v.logger.Debug("searching for config in path", "path", in) v.logger.Debug("searching for config in path", "path", in)
if v.configType != "" && stringInSlice(v.configType,SupportedExts) {
if b, _ := exists(v.fs, filepath.Join(in, v.configName)); b {
return filepath.Join(in, v.configName)
}
}
for _, ext := range SupportedExts { for _, ext := range SupportedExts {
v.logger.Debug("checking if file exists", "file", filepath.Join(in, v.configName+"."+ext)) v.logger.Debug("checking if file exists", "file", filepath.Join(in, v.configName+"."+ext))
if b, _ := exists(v.fs, filepath.Join(in, v.configName+"."+ext)); b { if b, _ := exists(v.fs, filepath.Join(in, v.configName+"."+ext)); b {
@ -35,12 +42,6 @@ func (v *Viper) searchInPath(in string) (filename string) {
} }
} }
if v.configType != "" {
if b, _ := exists(v.fs, filepath.Join(in, v.configName)); b {
return filepath.Join(in, v.configName)
}
}
return "" return ""
} }