-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
71 lines (56 loc) · 1.24 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
package main
import (
"github.com/BurntSushi/toml"
"github.com/cameliot/alpaca"
"io/ioutil"
)
type HttpConfig struct {
Listen string `toml:"listen"`
}
type BrokerConfig struct {
Uri string `toml:"uri"`
}
type MetaConfig struct {
Topic string `toml:"topic"`
}
type WatchConfig struct {
Request string `toml:"request"`
Success string `toml:"success"`
Error string `toml:"error"`
}
type ServiceConfig struct {
Handle string `toml:"handle"`
Topic string `toml:"topic"`
Watches map[string]*WatchConfig `toml:"watch"`
}
type Config struct {
Herd string `toml:"name"`
Http HttpConfig `toml:"http"`
Broker BrokerConfig `toml:"broker"`
Meta MetaConfig `toml:"meta"`
Services []*ServiceConfig `toml:"services"`
}
func LoadConfig(filename string) *Config {
data, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
config := Config{}
_, err = toml.Decode(string(data), &config)
if err != nil {
panic(err)
}
return &config
}
/*
Create alpaca routes from config
*/
func (self *Config) AlpacaRoutes() alpaca.Routes {
routes := alpaca.Routes{
"meta": self.Meta.Topic,
}
for _, service := range self.Services {
routes[service.Handle] = service.Topic
}
return routes
}