-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
80 lines (60 loc) · 2.07 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/lucas-gaitzsch/pdf-turtle/config"
"github.com/lucas-gaitzsch/pdf-turtle/loopback"
"github.com/lucas-gaitzsch/pdf-turtle/server"
"github.com/lucas-gaitzsch/pdf-turtle/services"
"github.com/lucas-gaitzsch/pdf-turtle/services/assetsprovider"
"github.com/lucas-gaitzsch/pdf-turtle/services/bundles"
"github.com/lucas-gaitzsch/pdf-turtle/services/renderer"
"github.com/lucas-gaitzsch/pdf-turtle/utils/logging"
"github.com/rs/zerolog/log"
"github.com/alexflint/go-arg"
)
func initConfigByArgs(ctx context.Context) context.Context {
var c config.Config
arg.MustParse(&c)
return config.ContextWithConfig(ctx, c)
}
func initServicesCtx(ctx context.Context) context.Context {
servicesCtx := ctx
rendererService := renderer.NewRendererBackgroundService(ctx)
servicesCtx = context.WithValue(servicesCtx, config.ContextKeyRendererService, rendererService)
assetsProviderService := assetsprovider.NewAssetsProviderService()
servicesCtx = context.WithValue(servicesCtx, config.ContextKeyAssetsProviderService, assetsProviderService)
bundleProviderService := bundles.NewBundleProviderService()
servicesCtx = context.WithValue(servicesCtx, config.ContextKeyBundleProviderService, bundleProviderService)
return servicesCtx
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
ctx = initConfigByArgs(ctx)
logging.InitLogger(ctx)
log.Info().Msg("Hey dude 👋 .. I am Karl, your turtle for today 🐢")
// init services
servicesCtx := initServicesCtx(ctx)
// init loopback server
srvLoopback := loopback.Server{}
srvLoopback.Serve(servicesCtx)
// init server
srv := server.Server{}
srv.Serve(servicesCtx)
// listen to os signals
osSignals := make(chan os.Signal, 1)
signal.Notify(osSignals, syscall.SIGINT, syscall.SIGTERM)
<-osSignals
// cleanup resources
log.Info().Msg("shutting service down...")
srv.Close(ctx)
servicesCtx.
Value(config.ContextKeyRendererService).(services.RendererBackgroundService).
Close()
cancel()
// exit
log.Info().Msg("🐢 bye bye dude.")
os.Exit(0)
}