forked from MaibornWolff/vbump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (36 loc) · 1.15 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
package main
import (
"log"
"net/http"
"time"
"github.com/maibornwolff/vbump/adapter"
logrus "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
func main() {
logger := logrus.New()
logger.Formatter = &logrus.JSONFormatter{}
w := logger.Writer()
defer w.Close()
log.SetOutput(w)
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()
logger.Info("Server is starting...")
fileProvider := adapter.New(*datadir)
version := NewVersion(fileProvider)
handler := NewHandler(version, logger)
router := handler.GetRouter()
server := &http.Server{
Addr: *listenAddr,
Handler: router,
ErrorLog: log.New(w, "", 0),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 15 * time.Second,
}
logger.Infof("Server is ready to handle requests at %v", *listenAddr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("Could not listen on %v: %v\n", *listenAddr, err)
}
}