summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/viper/viper_go1_16.go
blob: e10172fa3fba1f5ea6fe7031e16871c6d9284a5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build go1.16 && finder
// +build go1.16,finder

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
}