forked from pingcap/dead-mans-switch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
54 lines (44 loc) · 778 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
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"os"
"time"
"github.com/prometheus/alertmanager/template"
"gopkg.in/yaml.v2"
)
type Config struct {
Interval time.Duration
Notify *Notify
Evaluate *Evaluate
}
type Notify struct {
Pagerduty *Pagerduty
Webhook *Webhook
}
type Webhook struct {
Url string
Method string
}
type Pagerduty struct {
Key string
}
type EvaluateType string
const (
EvaluateEqual EvaluateType = "equal"
EvaluateInclude EvaluateType = "include"
)
type Evaluate struct {
Data template.Data
Type EvaluateType
}
func ParseConfig(path string) (*Config, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
config := &Config{}
err = yaml.NewDecoder(file).Decode(config)
if err != nil {
return nil, err
}
return config, nil
}