-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
57 lines (50 loc) · 1.2 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
// Copyright 2020 Changkun Ou. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package main
import (
"log"
"os"
"gopkg.in/yaml.v3"
)
type config struct {
Addr string `yaml:"addr"`
Sender struct {
Mailgun struct {
Email string `yaml:"email"`
Enable bool `yaml:"enable"`
Domain string `yaml:"domain"`
APIBase string `yaml:"apibase"`
} `yaml:"mailgun"`
Custom struct {
SMTPHost string `yaml:"smtp_host"`
SMTPPort string `yaml:"smtp_port"`
Email string `yaml:"email"`
Username string `yaml:"username"`
Passcode string `yaml:"passcode"`
} `yaml:"custom"`
} `yaml:"sender"`
Default struct {
Notifiers []string `yaml:"notifiers"`
Interval int `yaml:"interval"`
} `yaml:"default"`
Monitors []*monitor `yaml:"monitors"`
}
func (c *config) parse() {
f := os.Getenv("UPBOT_CONF")
d, err := os.ReadFile(f)
if err != nil {
d, err = os.ReadFile("./configs/config.yml")
if err != nil {
log.Fatalf("cannot read config, err: %v\n", err)
}
}
err = yaml.Unmarshal(d, c)
if err != nil {
log.Fatalf("cannot parse config, err: %v\n", err)
}
}
var conf config
func init() {
conf.parse()
}