-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.go
38 lines (31 loc) · 984 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
package main
import (
"net/http"
"github.com/gorilla/context"
"github.com/gorilla/mux"
"github.com/haydenwoodhead/burner.kiwi/burner"
"github.com/haydenwoodhead/gateway"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&log.JSONFormatter{})
cfg, db, email, listenAddr := mustParseConfig()
s, err := burner.New(cfg, db, email)
if err != nil {
log.Fatalf("Failed to setup new burner: %v", err)
}
log.Info("Starting burner.kiwi")
if cfg.UsingLambda {
log.Fatal(gateway.ListenAndServe("", context.ClearHandler(s.Router))) // wrap mux in ClearHandler as per docs to prevent leaking memory
return
}
if cfg.EmitMetrics {
metricMux := mux.NewRouter()
metricMux.Handle("/metrics", promhttp.Handler())
go func() {
log.Fatal(http.ListenAndServe(cfg.MetricPort, context.ClearHandler(metricMux)))
}()
}
log.Fatal(http.ListenAndServe(listenAddr, context.ClearHandler(s.Router)))
}