mirror of https://github.com/spf13/viper.git
Merge pull request #20 from mohae/fix-windows-path
update to consistently use filepath instead of path and add looking in o...
This commit is contained in:
commit
4dcc7d4916
17
viper.go
17
viper.go
|
@ -25,7 +25,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -650,10 +649,10 @@ func searchInPath(in string) (filename string) {
|
||||||
jww.DEBUG.Println("Searching for config in ", in)
|
jww.DEBUG.Println("Searching for config in ", in)
|
||||||
for _, ext := range SupportedExts {
|
for _, ext := range SupportedExts {
|
||||||
|
|
||||||
jww.DEBUG.Println("Checking for", path.Join(in, configName+"."+ext))
|
jww.DEBUG.Println("Checking for", filepath.Join(in, configName+"."+ext))
|
||||||
if b, _ := exists(path.Join(in, configName+"."+ext)); b {
|
if b, _ := exists(filepath.Join(in, configName+"."+ext)); b {
|
||||||
jww.DEBUG.Println("Found: ", path.Join(in, configName+"."+ext))
|
jww.DEBUG.Println("Found: ", filepath.Join(in, configName+"."+ext))
|
||||||
return path.Join(in, configName+"."+ext)
|
return filepath.Join(in, configName+"."+ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,13 +668,19 @@ func findConfigFile() (string, error) {
|
||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cwd, _ := findCWD()
|
|
||||||
|
|
||||||
|
cwd, _ := findCWD()
|
||||||
file := searchInPath(cwd)
|
file := searchInPath(cwd)
|
||||||
if file != "" {
|
if file != "" {
|
||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try the current working directory
|
||||||
|
wd, _ := os.Getwd()
|
||||||
|
file = searchInPath(wd)
|
||||||
|
if file != "" {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
return "", fmt.Errorf("config file not found in: %s", configPaths)
|
return "", fmt.Errorf("config file not found in: %s", configPaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue