-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
52 lines (43 loc) · 1.4 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
package main
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
"gopkg.in/alecthomas/kingpin.v2"
"maibornwolff/vbump/adapter"
"maibornwolff/vbump/service"
)
var (
numberOfBumps = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "vbump_bumps_total",
Help: "Number of bumps tracked by vbump, labelled with project name and semVer element",
},
[]string{"project", "element"},
)
)
func init() {
prometheus.MustRegister(numberOfBumps)
}
func main() {
listenAddr := kingpin.Flag("listen", "Address to listen on.").Short('l').Default(":8080").String()
dataDir := kingpin.Flag("datadir", "Directory path for storing version files (must exist).").Short('d').Required().String()
kingpin.Parse()
log.Info().Msg("Server is starting...")
fileProvider := adapter.NewFileProvider(*dataDir)
versionManager := service.NewVersionManager(fileProvider)
handler := NewHandler(versionManager)
router := handler.GetRouter()
server := &http.Server{
Addr: *listenAddr,
Handler: router,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 15 * time.Second,
}
log.Info().Str("listenAddr", *listenAddr).Msg("Server is ready to handle requests")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatal().Str("listenAddr", *listenAddr).Err(err).Msg("Failed to listen")
}
}