-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (49 loc) · 1.21 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
package main
import (
"captintheconvo-backend/database"
"captintheconvo-backend/models"
"captintheconvo-backend/routes"
"fmt"
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func init() {
// Load environment variables from .env file
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file: %v", err)
}
}
func main() {
// Connect to the database
database.ConnectDB()
// Auto-migrate models
database.DB.AutoMigrate(
&models.User{},
&models.Thread{},
&models.Tag{},
&models.Comment{},
)
// Create a router
router := gin.Default()
// Register routes
routes.AuthRoutes(router)
routes.ThreadRoutes(router)
routes.AdminRoutes(router)
routes.CommentRoutes(router)
routes.TagRoutes(router)
host := os.Getenv("APP_HOST") // Render sets the PORT environment variable
if host == "" {
host = "localhost" // Default to 8080 for local testing
}
port := os.Getenv("APP_PORT") // Render sets the PORT environment variable
if port == "" {
port = "8080" // Default to 8080 for local testing
}
fmt.Println("APP_HOST:", os.Getenv("APP_HOST"))
fmt.Println("APP_PORT:", os.Getenv("APP_PORT"))
// Start the server
router.Run(fmt.Sprintf("%s:%s", host, port))
}