-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (39 loc) · 914 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
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"log"
"net/http"
"time"
"go.uber.org/zap"
)
var listen string
var l *zap.Logger
func main() {
var err error
flag.StringVar(&listen, "listen", ":8000", "Listen address")
level := zap.LevelFlag("log", zap.InfoLevel, "zap logging level")
flag.Parse()
config := zapConfig()
config.Level = zap.NewAtomicLevelAt(*level)
l, err = config.Build()
if err != nil {
log.Fatalf("failed to initialize zap logger: %v", err)
}
defer l.Sync()
app, err := NewDatetime()
if err != nil {
l.Panic("failed to create datetime", zap.Error(err))
}
server := &http.Server{
Addr: listen,
Handler: app,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
l.Info("server is listening", zap.String("addr", listen))
err = server.ListenAndServe()
if err != nil {
l.Panic("server failed", zap.Error(err))
}
}