The main server, and probably only repository in this org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
643 B

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
}