-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (63 loc) · 2.7 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
package main
import (
"ahyalfan/golang_e_money/dto"
"ahyalfan/golang_e_money/internal/api"
"ahyalfan/golang_e_money/internal/component"
"ahyalfan/golang_e_money/internal/config"
"ahyalfan/golang_e_money/internal/middleware"
"ahyalfan/golang_e_money/internal/repository"
"ahyalfan/golang_e_money/internal/service"
"ahyalfan/golang_e_money/internal/sse"
"log"
"github.com/gofiber/fiber/v2"
)
func main() {
cnf := config.Get()
app := fiber.New()
// connection
dbConnection := component.GetDatabaseConnection(cnf)
// cacheConnection := component.GetCacheConnection() // kita coba ganti dengan redis
cacheConnection := repository.NewRedisCache(cnf)
// logrus logger
component.Log.Info("Starting app server")
// hub
hub := &dto.Hub{
NotificationChannel: make(map[int64]chan dto.NotificationData),
}
// repository
userRepository := repository.NewUser(dbConnection)
accountRepository := repository.NewAccount(dbConnection)
transactionRepository := repository.NewTransaction(dbConnection)
notificationRepository := repository.NewNotification(dbConnection)
templateRepository := repository.NewTemplate(dbConnection)
topupRepository := repository.NewTopup(dbConnection)
factorRepository := repository.NewFactor(dbConnection)
loginLog := repository.NewLoginLog(dbConnection)
// service
queueService := service.NewQueueService(cnf)
emailService := service.NewEmail(cnf, queueService)
factorService := service.NewFactor(factorRepository)
userService := service.NewUserService(userRepository, cacheConnection, emailService, factorService)
accountService := service.NewAccount(accountRepository)
notificationService := service.NewNotification(notificationRepository, templateRepository, hub)
transactionService := service.NewTransaction(accountRepository, transactionRepository, cacheConnection, dbConnection, notificationService)
midtransService := service.NewMidtrans(cnf)
topupService := service.NewTopupService(notificationService, topupRepository, midtransService, accountRepository, transactionRepository)
ipCheckerService := service.NewIpChecker()
fdsService := service.NewFds(ipCheckerService, loginLog)
// middleware
authMiddleware := middleware.Authenticate(userService)
api.NewAuth(app, userService, authMiddleware, fdsService)
api.NewMidtrans(app, midtransService, topupService)
api.NewAccount(app, accountService, authMiddleware)
api.NewTransfer(app, transactionService, authMiddleware, factorService)
api.NewNotification(app, notificationService, authMiddleware)
api.NewTopup(app, authMiddleware, topupService)
// sse
sse.NewNotificationSse(app, hub, authMiddleware)
api.NewNotFound(app)
err := app.Listen(cnf.Server.Host + ":" + cnf.Server.Port)
if err != nil {
log.Fatal(err.Error())
}
}