fix: config file search error

This commit is contained in:
amone-windows 2024-02-07 18:14:53 +08:00
parent 8f34134e70
commit 3924934ea9

12
file.go
View file

@ -26,6 +26,12 @@ 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 != "" {
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 {
@ -34,12 +40,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 ""
}