-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (34 loc) · 824 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/mdellandrea/minutes-server/lib/server"
"github.com/rs/zerolog"
)
func main() {
log := zerolog.New(os.Stderr).With().Timestamp().Logger()
zerolog.SetGlobalLevel(zerolog.InfoLevel)
s := server.Init(log)
go func() {
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM)
<-stopChan
log.Info().Msg("shutting down server")
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := s.Shutdown(ctx); err != nil {
log.Info().
Err(err).
Msg("http server error during shutdown")
}
}()
if err := s.ListenAndServe(); err != http.ErrServerClosed {
log.Info().
Err(err).
Msg("http server terminated unexpectedly")
}
}