-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (47 loc) · 1.14 KB
/
main.go
File metadata and controls
57 lines (47 loc) · 1.14 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
package main
import (
"fmt"
"time"
"gradspaceBK/config"
"gradspaceBK/controller"
"gradspaceBK/database"
"gradspaceBK/ws"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
RunServer()
}
//need sql based migration
// func Migrate() {
// database.DBConnection()
// session := database.Session.Db
// fmt.Println("Connected to database")
// database.MigrateDB(session)
// }
func RunServer() {
config.LoadConfig() // Load .env first
database.DBConnection()
// Start cleanup job
go func() {
ticker := time.NewTicker(24 * time.Hour)
defer ticker.Stop()
time.Sleep(1 * time.Minute)
if err := database.CleanupOldNotifications(); err != nil {
fmt.Printf("Initial notification cleanup failed: %v\n", err)
}
for range ticker.C {
if err := database.CleanupOldNotifications(); err != nil {
fmt.Printf("Notification cleanup error: %v\n", err)
}
}
}()
app := fiber.New()
// Static files and logger
app.Static("/api/v1/uploads", "./uploads")
app.Use(logger.New())
// **WebSocket setup (BEFORE other routes)**
ws.SetupWebSocket(app)
controller.SetupRouter(app)
app.Listen(":8003")
}