-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (33 loc) · 806 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
package main
import (
"context"
"log"
"os/signal"
"syscall"
"time"
"go.uber.org/zap"
"mascot/internal/app"
"mascot/internal/config"
)
const serviceName = "mascot"
func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
logger, err := zap.NewDevelopment()
if err != nil {
log.Fatal(err)
}
logger = logger.With(zap.String("service", serviceName))
cfg, err := config.Init(serviceName)
if err != nil {
logger.Fatal("init config", zap.Error(err))
}
service := app.NewService(logger)
go service.Start(ctx, cfg)
<-ctx.Done()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := service.Shutdown(ctx); err != nil {
logger.Fatal("shutdown service", zap.Error(err))
}
}