-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (41 loc) · 964 Bytes
/
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
package main
import (
"context"
"fmt"
"github.com/euler-b/maxInventoryProject/database"
"github.com/euler-b/maxInventoryProject/internal/api"
"github.com/euler-b/maxInventoryProject/internal/repository"
"github.com/euler-b/maxInventoryProject/internal/service"
"github.com/euler-b/maxInventoryProject/settings"
"github.com/labstack/echo/v4"
"go.uber.org/fx"
)
func main() {
app := fx.New(
fx.Provide(
context.Background,
settings.New,
database.New,
repository.New,
service.New,
api.New,
echo.New,
),
fx.Invoke(
setLifeCycle,
),
)
app.Run()
}
func setLifeCycle(lc fx.Lifecycle, a *api.API, s *settings.Settings, e *echo.Echo) {
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error { // el context usado aqui es el propio de la libreria fx
address := fmt.Sprintf("%s:%s", s.Host, s.Port)
go a.Start(e, address)
return nil
},
OnStop: func(ctx context.Context) error {
return nil
},
})
}