package config import ( "os" "gopkg.in/yaml.v2" ) // Config is application configuration. type Config struct { DB struct { FileName string `yaml:"file_name"` } `yaml:"db"` } // Load loads the first valid config file from the list of file paths. func Load(filePaths ...string) (Config, error) { file, err := os.Open(filePaths[0]) if err != nil { if len(filePaths) > 1 { return Load(filePaths[1:]...) } return Config{}, err } config := Config{} err = yaml.NewDecoder(file).Decode(&config) if err != nil { if len(filePaths) > 1 { return Load(filePaths[1:]...) } return Config{}, err } return config, nil }