-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
78 lines (64 loc) · 1.63 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"log"
"time"
"go-challenge/config"
"go-challenge/database"
"go-challenge/internals/handlers"
"go-challenge/internals/notification"
"go-challenge/internals/repository"
"go-challenge/internals/services"
"go-challenge/pkg/httpclient"
"go-challenge/server"
"go.uber.org/fx"
)
// @title Go Open Food Facts Changelenge
// @version 1.0
// @description This project needs to realize synchronization with Open Food Facts open data and allow CRUD operations with data
// @termsOfService http://swagger.io/terms/
// @contact.name Eclésio F Melo Júnior
// @contact.url https://ecles.io
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host http://localhost:8080
// @BasePath /
func main() {
app := fx.New(
fx.Provide(
config.NewConfig,
database.NewConnection,
httpclient.NewHTTPClient,
notification.NewEmailer,
notification.NewImportationNotifier,
),
fx.Provide(
repository.NewProductRespository,
repository.NewImportRepository,
),
fx.Provide(
services.NewHealthcheck,
services.NewImportation,
services.NewProduct,
handlers.NewHealthcheckHandler,
handlers.NewProductsHandler,
server.NewServer,
),
fx.Invoke(
server.ImportJob,
server.NewRegister,
),
)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := app.Start(ctx); err != nil {
log.Fatal(err)
}
<-app.Done()
stopCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := app.Stop(stopCtx); err != nil {
log.Fatal(err)
}
}