-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (39 loc) · 979 Bytes
/
Copy pathmain.go
File metadata and controls
48 lines (39 loc) · 979 Bytes
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
package main
import (
"log"
"os"
"github.com/joho/godotenv"
"stanford-uni-students-api/config"
"stanford-uni-students-api/db"
"stanford-uni-students-api/router"
)
func main() {
// Load environment variables from .env file
if err := godotenv.Load(); err != nil {
log.Println("Warning: .env file not found, using environment variables")
}
// Initialize configuration
cfg := config.LoadConfig()
// Initialize database
database, err := db.InitDB(cfg)
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
defer database.Close()
// Run migrations
if err := db.RunMigrations(database); err != nil {
log.Printf("Failed to run migrations: %v", err)
return
}
// Setup router
r := router.SetupRouter(database)
// Start server
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("Server starting on port %s", port)
if err := r.Run(":" + port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}