-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
59 lines (53 loc) · 1.49 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"errors"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"path/filepath"
)
type Configure struct {
Telegram struct {
Token string `yaml:"token"`
ChatID int64 `yaml:"chatID"`
Enable bool `yaml:"enable"`
Debug bool `yaml:"debug"`
} `yaml:"telegram"`
PagerDuty struct {
RoutingKey string `yaml:"routingKey"`
ApiEndpoint string `yaml:"apiEndpoint"`
Enable bool `yaml:"enable"`
Debug bool `yaml:"debug"`
ClientUrl string `yaml:"clientUrl"`
ImagesSrc string `yaml:"imagesSrc"`
ImagesHref string `yaml:"imagesHref"`
ImagesAlt string `yaml:"imagesAlt"`
VoiceCallAlertWildcard []string `yaml:"voiceCallAlertWildcard"`
} `yaml:"pagerDuty"`
}
func (c *Configure) ParseConfig(data []byte) error {
if err := yaml.Unmarshal(data, c); err != nil {
return err
}
if c.Telegram.Token == "" || c.Telegram.ChatID == 0 {
return errors.New("telegram Token or ChatID is empty: must have some values")
}
return nil
}
func ProcessConfigParameters(configFile string) (cfg Configure, err error) {
// read and decode config
execPath, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadFile(execPath + "/" + configFile)
if err != nil {
log.Fatal(err)
}
var config Configure
if err := config.ParseConfig(data); err != nil {
log.Fatal("error in ParseConfig ", err)
}
return config, err
}