-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
70 lines (55 loc) · 1.46 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
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
// Config holds config for the whole thing.
// It also has some context info for now. We may move it to "Context" type
type Config struct {
// Slack stuff
Slacks map[string]*ConfigSlack `yaml:"slack"`
// Telegram stuff
Telegrams map[string]*ConfigTelegram `yaml:"telegram"`
// Mailgun stuff
Mailguns map[string]*ConfigMailgun `yaml:"mailgun"`
// Twilio stuff
Twilios map[string]*ConfigTwilio `yaml:"twilio"`
}
// ConfigSlack is a config block for Slack
type ConfigSlack struct {
Key string `yaml:"key"`
}
// ConfigTelegram is a config block for Telegram
type ConfigTelegram struct {
Token string `yaml:"token"`
ChatID string `yaml:"chat_id"`
}
// ConfigMailgun is a config block for Mailgun
type ConfigMailgun struct {
Domain string `yaml:"domain"`
Key string `yaml:"key"`
}
// ConfigTwilio is the config for Twilio
type ConfigTwilio struct {
Sid string `yaml:"sid"`
Token string `yaml:"token"`
From string `yaml:"from"`
To string `yaml:"to"`
}
// NewConfig is a constructor and make a new Config object
// The profile name comes from a command line
func NewConfig(fn string, profileName string) *Config {
var cfg Config
rawData, err := ioutil.ReadFile(fn)
if err != nil {
panic(err)
}
err = yaml.Unmarshal([]byte(rawData), &cfg)
if err != nil {
log.Fatalf("error: %v", err)
}
log.Printf("read config => %v", cfg)
log.Printf("read config => %v", cfg.Slacks)
return &cfg
}