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 (
"fmt"
"sort"
"go.eth.moe/dispatch/config"
"go.eth.moe/flag"
"go.eth.moe/logger"
)
var (
configPath = flag.Custom("config-path", "", "path to config.json", flag.RequiredString)
)
func main() {
flag.Parse()
configPath := (*configPath).(string)
log := logger.Background()
cfg, err := config.ParseFile(configPath)
if err != nil {
log.AddField("config-path", configPath)
log.WithError(err).Fatal("could not parse config")
}
var names []string
for name := range cfg.RulesByName {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
rule := cfg.RulesByName[name]
fmt.Printf("%v:\n", name)
fmt.Printf("- triggers:\n")
for _, trigger := range rule.Triggers {
fmt.Printf(" - url: %v\n", trigger.URL)
}
fmt.Printf("- actions:\n")
for _, action := range rule.Actions {
switch action.Kind {
case config.HTTPAction:
fmt.Printf(" - url: %v\n", action.URL)
case config.MQTTAction:
fmt.Printf(" - mqtt: %v\n", action.MQTT)
fmt.Printf(" - value: %v\n", action.Value)
}
}
}
}
|