-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
42 lines (33 loc) · 910 Bytes
/
config.go
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
33
34
35
36
37
38
39
40
41
42
package main
import (
"errors"
"io/ioutil"
"gopkg.in/yaml.v2"
)
// YamlConfig is the top level of configuration file.
// It contains the information of the version, notifiers and watchers.
type YamlConfig struct {
Version string
Notifiers []map[string]interface{}
Watchers []map[string]interface{}
}
// LoadConfig reads and parses the config file preliminarily.
// It checks the version of the config and returns map structures for later use.
func LoadConfig(path string) (YamlConfig, error) {
var config YamlConfig
yamlFile, err := ioutil.ReadFile(path)
if err != nil {
return config, err
}
err = yaml.Unmarshal([]byte(yamlFile), &config)
if err != nil {
return config, err
}
if config.Version == "1.0" {
return config, errors.New("Please upgrade the config file")
}
if config.Version != "1.1" {
return config, errors.New("Invalid config version")
}
return config, nil
}