-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (33 loc) · 813 Bytes
/
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
package main
import (
"flag"
"net/http"
gologging "github.com/sigmonsays/go-logging"
)
var defaultConf = `
http_addr: 127.0.0.1:8944
commands: []
# EOF
`
func main() {
configfile := "/etc/instructd.yaml"
loglevel := "INFO"
flag.StringVar(&configfile, "config", configfile, "specify config file")
flag.StringVar(&loglevel, "loglevel", loglevel, "specify log level")
flag.Parse()
gologging.SetLogLevel(loglevel)
cfg := &Config{}
cfg.LoadYamlBuffer([]byte(defaultConf))
cfg.LoadYaml(configfile)
cfg.PrintConfig()
api := &CommandHandler{
Commands: cfg.Commands,
Auth: NewAuth(cfg.Auth),
Security: cfg.Security,
}
log.Infof("Listening at %s", cfg.HTTPAddr)
err := http.ListenAndServe(cfg.HTTPAddr, api)
if err != nil {
ExitError("ListenAndServe %s: %s", cfg.HTTPAddr, err)
}
}