-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (52 loc) · 1.5 KB
/
main.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
package main
import (
"flag"
"fmt"
"github.com/Civil/graphite-delay-test/checker"
"github.com/Civil/graphite-delay-test/config"
"github.com/uber-go/zap"
"io/ioutil"
"net/http"
"path/filepath"
"gopkg.in/yaml.v2"
)
var logger zap.Logger
type configFileStruct map[string]config.CheckerConfig
func main() {
configFile := flag.String("c", "delay.yaml", "Path to the config file")
listenAddress := flag.String("l", ":8099", "ExpVars http listener")
flag.Parse()
logger = zap.New(zap.NewTextEncoder())
logger.Info("Initializing...")
filename, err := filepath.Abs(*configFile)
if err != nil {
logger.Fatal("Error getting file name", zap.Error(err))
}
logger.Info("Loading config", zap.String("name", *configFile))
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
logger.Fatal("Error reading config file", zap.Error(err))
}
cfg := make(configFileStruct)
err = yaml.Unmarshal(yamlFile, &cfg)
if err != nil {
logger.Fatal("Error reading config file", zap.Error(err))
}
if len(cfg) == 0 {
logger.Fatal("No checkers defined in the config file!")
}
exit := make(chan struct{})
for name, c := range cfg {
err = config.Validate(&c, name)
fmt.Printf("%+v\n", c)
if err != nil {
logger.Error("Error validating config file", zap.Error(err))
return
}
// TODO: Actually pass the config!
chk := checker.NewChecker(c, name, exit, logger)
go chk.Run()
}
logger.Info("Started")
logger.Fatal("Failed to start HTTP server", zap.Error(http.ListenAndServe(*listenAddress, nil)))
}