-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (58 loc) · 2.28 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
// TODO
/*
- simple message in run
*/
package main
import (
"context"
"fmt"
"os"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/api"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/authService"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/bookService"
database "github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/database/sqlc"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/email"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/token"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/util"
"github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-Mayhul-Jindal/worker"
"github.com/go-playground/validator/v10"
"github.com/jackc/pgx/v5/pgxpool"
razorpay "github.com/razorpay/razorpay-go"
)
func main() {
// config
config, err := util.LoadConfig(".")
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to load config: %v\n", err)
os.Exit(1)
}
// validator
validator := validator.New()
// database
dbPool, err := pgxpool.New(context.Background(), config.DB_URL)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err)
os.Exit(1)
}
defer dbPool.Close()
database := database.NewPostgresStore(dbPool)
// tokenMaker
tokenMaker := token.NewPasetoMaker(config.TOKEN_SYMMETRIC_KEY)
// emailer
emailer := email.NewGmailSender(config.EMAIL_SENDER_NAME, config.EMAIL_SENDER_ADDRESS, config.EMAIL_SENDER_PASSWORD)
// racor pay client
razorPayClient := razorpay.NewClient(config.RAZORPAY_KEY_ID, config.RAZORPAY_KEY_SECRET)
// worker service
worker := worker.NewWorker(database, emailer)
// auth service with logger attached (onion architecture)
authService := authService.NewLoggingService(
authService.NewManager(config, tokenMaker, database, worker),
)
// book service with logger attached (onion architecture)
bookService := bookService.NewLoggingService(
bookService.NewManager(database, razorPayClient),
)
// json gateway service
server := api.NewAPIServer(config.SERVER_PORT, authService, bookService, tokenMaker, validator)
server.Run()
}