-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathciri.go
More file actions
49 lines (43 loc) · 993 Bytes
/
ciri.go
File metadata and controls
49 lines (43 loc) · 993 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
//_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"github.com/boiler/ciri/config"
"github.com/boiler/ciri/handler"
"github.com/boiler/ciri/metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
log.Print("start")
cfg := config.NewConfig()
metrics.Init(cfg)
h := handler.New(cfg)
h.Init()
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
go func() {
for _ = range sigc {
fmt.Println("TERM signal received")
h.Terminate()
fmt.Println("EXIT")
os.Exit(0)
}
}()
httpMux := http.NewServeMux()
httpMux.HandleFunc("/", http.HandlerFunc(h.ServeHTTP))
httpMux.Handle("/metrics", promhttp.Handler())
httpServer := &http.Server{
Addr: cfg.Listen,
Handler: httpMux,
}
httpServer.SetKeepAlivesEnabled(false)
log.Printf("http server starts listening on %s", cfg.Listen)
if err := httpServer.ListenAndServe(); err != nil {
log.Fatal(err)
}
}