-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (45 loc) · 1.53 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
package main
import (
"log/slog"
"os"
"os/signal"
"syscall"
_ "time/tzdata" // Important b/c some servers don't allow access to timezone file so we need to embed it with our binary.
_ "go.uber.org/automaxprocs" // Automatically set GOMAXPROCS to match Linux container CPU quota.
http "github.com/bartmika/databoutique-backend/internal/inputport/httptransport"
)
type Application struct {
Logger *slog.Logger
HTTPTransport http.InputPortServer
}
// NewApplication is application construction function which is automatically called by `Google Wire` dependency injection library.
func NewApplication(
loggerp *slog.Logger,
httpTransport http.InputPortServer,
) Application {
return Application{
Logger: loggerp,
HTTPTransport: httpTransport,
}
}
func (a Application) Execute() {
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGUSR1)
// Run in background the HTTP server.
go a.HTTPTransport.Run()
a.Logger.Info("Application started")
// Run the main loop blocking code while other input ports run in background.
<-done
a.Shutdown()
}
func (a Application) Shutdown() {
a.HTTPTransport.Shutdown()
a.Logger.Info("Application shutdown")
}
// main function is the main entry point into the code.
func main() {
// Call the `InitializeEvent` function which will call `Google Wire` dependency injection package to load up all this projects dependencies together.
Application := InitializeEvent()
// Start the application!
Application.Execute()
}