spf13--viper/viper_go1_16.go
Mark Sagi-Kazar 4e595cec77 feat: use io/fs for searching files on Go 1.16+
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-21 18:01:05 +02:00

32 lines
645 B
Go

//go:build go1.16
// +build go1.16
package viper
import (
"fmt"
"github.com/spf13/afero"
)
// Search all configPaths for any config file.
// Returns the first path that exists (and is a config file).
func (v *Viper) findConfigFile() (string, error) {
finder := finder{
paths: v.configPaths,
fileNames: []string{v.configName},
extensions: SupportedExts,
withoutExtension: v.configType != "",
}
file, err := finder.Find(afero.NewIOFS(v.fs))
if err != nil {
return "", err
}
if file == "" {
return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)}
}
return file, nil
}