-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (42 loc) · 1.09 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
package main
import (
"checkr.com/idempotent-requests/pkg/captures/captures_mongo"
"checkr.com/idempotent-requests/pkg/http"
"checkr.com/idempotent-requests/pkg/mongodb"
"checkr.com/idempotent-requests/pkg/tracing"
"context"
"github.com/opentracing/opentracing-go"
"go.uber.org/zap"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
logger, _ := zap.NewProduction()
zap.ReplaceGlobals(logger)
defer logger.Sync()
var tracer tracing.Tracer
if tracing.GetConfig().TracingEnabled {
tracer = tracing.NewTracer()
opentracing.SetGlobalTracer(tracer.OpentracingTracer())
defer tracer.Stop()
}
mongo := mongodb.NewClient(tracer)
capturesRepo := captures_mongo.NewRepository(mongo)
httpServer := http.NewServer(tracer, capturesRepo)
go httpServer.Start()
waitForShutdownSignal()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
mongo.Shutdown(ctx)
httpServer.Stop(ctx)
}
func waitForShutdownSignal() {
signalChan := make(chan os.Signal, 1)
signal.Notify(
signalChan,
syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT,
)
<-signalChan
}