-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (38 loc) · 1.13 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
package main
import (
"github.com/ehsandavari/go-context-plus"
"github.com/ehsandavari/go-graceful-shutdown"
"github.com/joho/godotenv"
"health-check/application"
"health-check/infrastructure"
"health-check/persistence"
"health-check/presentation"
"log"
)
func main() {
log.SetFlags(log.LstdFlags | log.Llongfile)
loadEnv()
run()
}
func loadEnv() {
if err := godotenv.Load(); err != nil {
log.Fatalln("error in loading .env file", err)
}
}
func run() {
ctx := contextplus.Background()
newInfrastructure := infrastructure.NewInfrastructure()
newApplication := application.NewApplication(newInfrastructure, persistence.NewPersistence(newInfrastructure))
newApplication.StartJobs(ctx)
newPresentation := presentation.NewPresentation(newInfrastructure, newApplication)
newPresentation.Setup()
newInfrastructure.ILogger.WithAny("config", newInfrastructure.SConfig).Info(ctx, "app config")
shutdownFunc := func() {
newPresentation.Close()
}
cleanupFunc := func() {
newApplication.StopJobs(ctx)
newInfrastructure.Close()
}
graceful.Shutdown(shutdownFunc, cleanupFunc, newInfrastructure.SConfig.Service.GracefulShutdownSecond)
}