-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (51 loc) · 1.16 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
package main
import (
"context"
"fmt"
"github.com/NikosSiak/Open-Banking-API/api/controllers/v1"
"github.com/NikosSiak/Open-Banking-API/api/middlewares/v1"
"github.com/NikosSiak/Open-Banking-API/api/routes/v1"
"github.com/NikosSiak/Open-Banking-API/lib"
"github.com/NikosSiak/Open-Banking-API/lib/sms"
"github.com/NikosSiak/Open-Banking-API/services"
"go.uber.org/fx"
)
// @title Open Banking Demo
// @version 1.0
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
func main() {
fx.New(
lib.Module,
routes.Module,
middlewares.Module,
controllers.Module,
services.Module,
sms.Module,
fx.Invoke(bootstrap),
).Run()
}
func bootstrap(
lifecycle fx.Lifecycle,
handler lib.RequestHandler,
env lib.Env,
db lib.Database,
routes routes.Routes,
) {
lifecycle.Append(fx.Hook{
OnStart: func(context.Context) error {
fmt.Println("Starting Server")
go func() {
routes.Setup()
handler.Gin.Run(":" + env.ServerPort)
}()
return nil
},
OnStop: func(ctx context.Context) error {
fmt.Println("Stopping Server")
db.Close(ctx)
return nil
},
})
}