-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathserver.go
43 lines (38 loc) · 1.04 KB
/
server.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 (
"github.com/AirHelp/rabbit-amazon-forwarder/mapping"
"github.com/AirHelp/rabbit-amazon-forwarder/supervisor"
log "github.com/sirupsen/logrus"
"net/http"
"os"
)
const (
LogLevel = "LOG_LEVEL"
)
func main() {
createLogger()
consumerForwarderMapping, err := mapping.New().Load()
if err != nil {
log.WithField("error", err.Error()).Fatalf("Could not load consumer - forwarder pairs")
}
supervisor := supervisor.New(consumerForwarderMapping)
if err := supervisor.Start(); err != nil {
log.WithField("error", err.Error()).Fatal("Could not start supervisor")
}
http.HandleFunc("/restart", supervisor.Restart)
http.HandleFunc("/health", supervisor.Check)
log.Info("Starting http server")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func createLogger() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.InfoLevel)
if logLevel := os.Getenv(LogLevel); logLevel != "" {
if level, err := log.ParseLevel(logLevel); err != nil {
log.Fatal(err)
} else {
log.SetLevel(level)
}
}
}