From ff657bbec2332e30fa76ec2a1969396a5a41dbd3 Mon Sep 17 00:00:00 2001 From: XYZ0901 Date: Mon, 7 Mar 2022 01:29:12 +0800 Subject: [PATCH] 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. --- viper_go1_15.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/viper_go1_15.go b/viper_go1_15.go index 19a771c..11397a1 100644 --- a/viper_go1_15.go +++ b/viper_go1_15.go @@ -27,6 +27,13 @@ func (v *Viper) findConfigFile() (string, error) { func (v *Viper) searchInPath(in string) (filename string) { 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 { 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 { @@ -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 "" }