forked from 0xERR0R/dex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (43 loc) · 1.16 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
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
func main() {
prometheus.MustRegister(newDockerCollector())
router := http.NewServeMux()
router.Handle("/metrics", promhttp.Handler())
server := &http.Server{
Addr: fmt.Sprintf(":%v", 8080),
Handler: router,
ReadTimeout: 5 * time.Second,
WriteTimeout: 120 * time.Second,
IdleTimeout: 15 * time.Second,
}
done := make(chan bool)
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
go func() {
<-quit
log.Info("Server is shutting down...")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Fatalf("Could not gracefully shutdown the server: %v\n", err)
}
close(done)
}()
log.Info("Server is ready to handle requests at :", 8080)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("Could not listen on %d: %v\n", 8080, err)
}
<-done
log.Info("Server stopped")
}