-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
153 lines (132 loc) · 4.66 KB
/
main.go
File metadata and controls
153 lines (132 loc) · 4.66 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"context"
"fmt"
"log"
"os"
"strings"
"github.com/Soup666/modelmaker/controller"
db "github.com/Soup666/modelmaker/database"
repositories "github.com/Soup666/modelmaker/repository"
"github.com/Soup666/modelmaker/router"
"github.com/Soup666/modelmaker/services"
firebase "firebase.google.com/go/v4"
"google.golang.org/api/option"
_ "github.com/joho/godotenv/autoload"
)
func printEnvironmentBanner() {
appEnv := os.Getenv("APP_ENV")
if appEnv == "" {
appEnv = "production"
}
// ANSI color codes
const (
colorRed = "\033[1;31m" // Bold Red
colorGreen = "\033[1;32m" // Bold Green
colorYellow = "\033[1;33m" // Bold Yellow
colorBlue = "\033[1;34m" // Bold Blue
colorMagenta = "\033[1;35m" // Bold Magenta
colorCyan = "\033[1;36m" // Bold Cyan
colorReset = "\033[0m"
)
var bannerColor, envText string
switch appEnv {
case "dev":
bannerColor = colorYellow
envText = "DEVELOPMENT"
case "staging":
bannerColor = colorCyan
envText = "STAGING"
case "test":
bannerColor = colorMagenta
envText = "TEST"
case "production":
bannerColor = colorGreen
envText = "PRODUCTION"
default:
bannerColor = colorRed
envText = strings.ToUpper(appEnv)
}
banner := []string{
"",
"╔════════════════════════════════════════╗",
"║ MODEL MAKER ║",
fmt.Sprintf("║ Environment: %-16s ║", envText),
"╚════════════════════════════════════════╝",
"",
}
for _, line := range banner {
fmt.Printf("%s%s%s\n", bannerColor, line, colorReset)
}
}
func main() {
// Print environment banner
printEnvironmentBanner()
// Set up the database connection
log.Println("Connecting to database...")
db.ConnectDatabase()
// Create a Firebase app instance
opt := option.WithCredentialsFile(os.Getenv("GOOGLE_CREDENTIALS_FILE"))
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
log.Fatalf("Failed to create Firebase app: %v", err)
}
// Create a Firebase auth client instance
authClient, err := app.Auth(context.Background())
if err != nil {
log.Fatalf("Failed to create Firebase auth client: %v", err)
}
// Set up the repositories
userRepo := repositories.NewUserRepository(db.DB)
taskRepo := repositories.NewTaskRepository(db.DB)
appFileRepo := repositories.NewAppFileRepository(db.DB)
reportsRepo := repositories.NewReportsRepository(db.DB)
collectionsRepo := repositories.NewCollectionsRepository(db.DB)
chatRepo := repositories.NewChatRepository(db.DB)
userAnalyticsRepo := repositories.NewUserAnalyticsRepository(db.DB)
// Set up the services
authService := services.NewAuthService(authClient, db.DB, userRepo)
userService := services.NewUserService(userRepo)
notificationService := services.NewNotificationService()
appFileService := services.NewAppFileServiceFile(appFileRepo)
storageService := services.NewKatapultStorageService()
taskService := services.NewTaskService(taskRepo, appFileService, chatRepo, notificationService, storageService)
visionService := services.NewVisionService()
reportsService := services.NewReportsService(reportsRepo)
collectionsService := services.NewCollectionsService(collectionsRepo)
userAnalyticsService := services.NewUserAnalyticsService(userAnalyticsRepo)
// Initialize Job Queue
taskService.StartWorker()
// Set up the controllers
authController := controller.NewAuthController(authService, userService)
uploadController := controller.NewUploadController(storageService)
objectController := controller.NewObjectController(storageService)
taskController := controller.NewTaskController(&taskService, appFileService, visionService, storageService)
visionController := controller.NewVisionController(visionService, taskRepo, &taskService)
reportsController := controller.NewReportsController(reportsService)
collectionsController := controller.NewCollectionsController(collectionsService)
userAnalyticsController := controller.NewUserAnalyticsController(userAnalyticsService)
notificationController := controller.NewNotificationController(notificationService)
// Set up the HTTP router
r := router.NewRouter(
authController,
taskController,
uploadController,
objectController,
visionController,
authService,
reportsController,
collectionsController,
userAnalyticsController,
notificationController,
)
// Start the server
port := os.Getenv("PORT")
if port == "" {
port = "3333"
}
log.Printf("Starting server on port %s...", port)
if err := r.Run(":" + port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}