-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (72 loc) · 2.4 KB
/
Copy pathmain.go
File metadata and controls
81 lines (72 loc) · 2.4 KB
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
79
80
81
package main
import (
"github.com/hiamthach108/dreon-notification/config"
"github.com/hiamthach108/dreon-notification/internal/repository"
"github.com/hiamthach108/dreon-notification/internal/service"
"github.com/hiamthach108/dreon-notification/pkg/cache"
"github.com/hiamthach108/dreon-notification/pkg/database"
"github.com/hiamthach108/dreon-notification/pkg/email"
"github.com/hiamthach108/dreon-notification/pkg/fcm"
"github.com/hiamthach108/dreon-notification/pkg/sms"
"github.com/hiamthach108/dreon-notification/presentation/events"
grpcserver "github.com/hiamthach108/dreon-notification/presentation/grpc"
"github.com/hiamthach108/dreon-notification/presentation/http"
"github.com/hiamthach108/dreon-notification/presentation/http/handler"
"github.com/hiamthach108/dreon-notification/presentation/worker"
"github.com/hiamthach108/dreon-sdk/logger"
"go.uber.org/fx"
"go.uber.org/fx/fxevent"
)
func main() {
app := fx.New(
fx.WithLogger(func(appLogger logger.ILogger) fxevent.Logger {
return &fxevent.ZapLogger{Logger: appLogger.GetZapLogger()}
}),
fx.Provide(
// Core
config.NewAppConfig,
newAppLogger,
cache.NewAppCache,
database.NewDbClient,
http.NewHttpServer,
email.NewResendEmailClient,
email.NewRenderer,
sms.NewMockClient, // TODO: remove this and use NewTwilioClient when Twilio is configured
sms.NewBodyRenderer,
fcm.NewClient,
// Events
events.NewLoggerAdapter,
events.NewAMQPPublisher,
events.NewAMQPSubscriber,
// Repositories
repository.NewNotificationRepository,
repository.NewPushTopicRepository,
repository.NewMailboxRepository,
repository.NewUserFCMTokenRepository,
// Services
service.NewNotificationSvc,
service.NewPushTopicSvc,
service.NewMailboxSvc,
service.NewUserFCMTokenSvc,
// Handlers
handler.NewNotificationHandler,
handler.NewPushTopicHandler,
handler.NewUserFCMTokenHandler,
// gRPC server (NotiInternal: notification management)
grpcserver.NewNotiInternalServer,
grpcserver.NewGRPCServer,
),
fx.Invoke(http.RegisterHooks),
fx.Invoke(grpcserver.RegisterHooks),
fx.Invoke(events.RunConsumers),
fx.Invoke(worker.RunPendingRetryWorker),
fx.Invoke(worker.RunScheduledNotificationWorker),
)
app.Run()
}
func newAppLogger(config *config.AppConfig) (logger.ILogger, error) {
return logger.NewLogger(logger.Config{
Service: config.App.Name,
Level: config.Logger.Level,
})
}