| 70 | } |
| 71 | |
| 72 | func readConfigFromPath(configPath string, log *zerolog.Logger) (Root, error) { |
| 73 | if configPath == "" { |
| 74 | return Root{}, errors.New("unable to find config file") |
| 75 | } |
| 76 | |
| 77 | file, err := os.Open(configPath) |
| 78 | if err != nil { |
| 79 | return Root{}, err |
| 80 | } |
| 81 | defer file.Close() |
| 82 | |
| 83 | var config Root |
| 84 | if err := yaml.NewDecoder(file).Decode(&config); err != nil { |
| 85 | if err == io.EOF { |
| 86 | log.Error().Msgf("Configuration file %s was empty", configPath) |
| 87 | return Root{}, nil |
| 88 | } |
| 89 | return Root{}, errors.Wrap(err, "error parsing YAML in config file at "+configPath) |
| 90 | } |
| 91 | |
| 92 | return config, nil |
| 93 | } |
| 94 | |
| 95 | // File change notifications from the watcher |
| 96 | |