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

  1. package config
  2. import (
  3. "os"
  4. "gopkg.in/yaml.v2"
  5. )
  6. // Config is application configuration.
  7. type Config struct {
  8. DB struct {
  9. FileName string `yaml:"file_name"`
  10. } `yaml:"db"`
  11. }
  12. // Load loads the first valid config file from the list of file paths.
  13. func Load(filePaths ...string) (Config, error) {
  14. file, err := os.Open(filePaths[0])
  15. if err != nil {
  16. if len(filePaths) > 1 {
  17. return Load(filePaths[1:]...)
  18. }
  19. return Config{}, err
  20. }
  21. config := Config{}
  22. err = yaml.NewDecoder(file).Decode(&config)
  23. if err != nil {
  24. if len(filePaths) > 1 {
  25. return Load(filePaths[1:]...)
  26. }
  27. return Config{}, err
  28. }
  29. return config, nil
  30. }