-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (44 loc) · 1.41 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
package main
import (
"context"
"os"
"os/signal"
"time"
"github.com/storybuilder/storybuilder/app/config"
"github.com/storybuilder/storybuilder/app/container"
"github.com/storybuilder/storybuilder/app/splash"
httpServer "github.com/storybuilder/storybuilder/transport/http/server"
metricsServer "github.com/storybuilder/storybuilder/transport/metrics/server"
)
func main() {
// show splash screen when starting
splash.Show(splash.StyleDefault)
// parse all configurations
cfg := config.Parse("./configs")
// prints all parsed configurations
cfg.Show()
// resolve the container using parsed configurations
ctr := container.Resolve(cfg)
// start the server to handle http requests
srv := httpServer.Run(cfg.AppConfig, ctr)
// start the server to expose application metrics
metricsServer.Run(cfg.AppConfig, ctr)
// enable graceful shutdown
c := make(chan os.Signal, 1)
// accept graceful shutdowns when quit via SIGINT (Ctrl+C)
// SIGKILL, SIGQUIT or SIGTERM (Ctrl+/) will not be caught
signal.Notify(c, os.Interrupt)
// block until a registered signal is received
<-c
// create a deadline to wait for
var wait time.Duration
// Doesn't block if no connections, but will otherwise wait
// until the timeout deadline.
ctx, cancel := context.WithTimeout(context.Background(), wait)
defer cancel()
// release resources
ctr.Destruct()
// gracefully stop the http server
httpServer.Stop(ctx, srv)
os.Exit(0)
}