viper_go1_16.go 662 B

1234567891011121314151617181920212223242526272829303132
  1. //go:build go1.16 && finder
  2. // +build go1.16,finder
  3. package viper
  4. import (
  5. "fmt"
  6. "github.com/spf13/afero"
  7. )
  8. // Search all configPaths for any config file.
  9. // Returns the first path that exists (and is a config file).
  10. func (v *Viper) findConfigFile() (string, error) {
  11. finder := finder{
  12. paths: v.configPaths,
  13. fileNames: []string{v.configName},
  14. extensions: SupportedExts,
  15. withoutExtension: v.configType != "",
  16. }
  17. file, err := finder.Find(afero.NewIOFS(v.fs))
  18. if err != nil {
  19. return "", err
  20. }
  21. if file == "" {
  22. return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)}
  23. }
  24. return file, nil
  25. }