-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
96 lines (75 loc) · 2.41 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"github.com/BurntSushi/toml"
)
type CrashHandlerType string
const (
FOGBUGZ CrashHandlerType = "fogbugz"
)
type ReleaseHandlerType string
const (
EMAIL ReleaseHandlerType = "email"
)
type config struct {
BindAddress string `toml:"bind_address"`
BindPort int `toml:"bind_port"`
AppConfigs map[string]appConfig `toml:"apps"`
}
type appConfig struct {
Name string `toml:"name"`
HockeyAppId string `toml:"hockeyapp_id"`
HockeyApiToken string `toml:"hockeyapp_api_token"`
CrashHandlerConfigs map[string]crashHandlerConfig `toml:"crash_handlers"`
ReleaseHandlerConfigs map[string]releaseHandlerConfig `toml:"release_handlers"`
}
type crashHandlerConfig struct {
HandlerType CrashHandlerType `toml:"type"`
HandlerConfig toml.Primitive `toml:"config"`
}
type releaseHandlerConfig struct {
HandlerType ReleaseHandlerType `toml:"type"`
HandlerConfig toml.Primitive `toml:"config"`
}
func (appConfig *appConfig) buildApp() (*App, error) {
crashHandlers := make([]NotificationHandler, 0)
for _, crashHandlerConfig := range appConfig.CrashHandlerConfigs {
switch crashHandlerConfig.HandlerType {
case FOGBUGZ:
crashHandler, err := NewFogbuzCrashHandler(crashHandlerConfig.HandlerConfig)
if err != nil {
return nil, err
}
crashHandlers = append(crashHandlers, crashHandler)
}
}
releaseHandlers := make([]NotificationHandler, 0)
for _, releaseHandlerConfig := range appConfig.ReleaseHandlerConfigs {
switch releaseHandlerConfig.HandlerType {
case EMAIL:
releaseHandler, err := NewEmailReleaseHandler(releaseHandlerConfig.HandlerConfig)
if err != nil {
return nil, err
}
releaseHandlers = append(releaseHandlers, releaseHandler)
}
}
return &App{appConfig.Name, appConfig.HockeyAppId, appConfig.HockeyApiToken, crashHandlers, releaseHandlers}, nil
}
func (handler *HookyAppHandler) ParseConfig(configFile string) error {
var config config
if _, err := toml.DecodeFile(configFile, &config); err != nil {
return err
}
apps := make(map[string]*App)
for _, appConfig := range config.AppConfigs {
app, err := appConfig.buildApp()
if err != nil {
return err
}
apps[appConfig.HockeyAppId] = app
}
handler.bindAddress = config.BindAddress
handler.bindPort = config.BindPort
handler.apps = apps
return nil
}