feat: initialize Go module and add main application entry point
- Add go.mod with required dependencies (Gin, GORM, PostgreSQL driver) - Create main.go with Gin router, CORS, sessions, and database initialization - Configure health check endpoint and auth route registration
This commit is contained in:
parent
ac0b09ad0e
commit
ee836fa4c8
3 changed files with 256 additions and 0 deletions
56
main.go
Normal file
56
main.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
"github.com/rideaware/rideaware-api/config"
|
||||
"github.com/rideaware/rideaware-api/models"
|
||||
"github.com/rideaware/rideaware-api/routes"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("No .env file found")
|
||||
}
|
||||
|
||||
// Initialize database
|
||||
db := config.InitDB()
|
||||
|
||||
// Auto migrate models
|
||||
if err := db.AutoMigrate(&models.User{}, &models.UserProfile{}); err != nil {
|
||||
log.Fatal("Failed to migrate database:", err)
|
||||
}
|
||||
|
||||
// Initialize Gin router
|
||||
r := gin.Default()
|
||||
|
||||
// CORS middleware
|
||||
r.Use(cors.Default())
|
||||
|
||||
// Session middleware
|
||||
store := cookie.NewStore([]byte(os.Getenv("SECRET_KEY")))
|
||||
r.Use(sessions.Sessions("session", store))
|
||||
|
||||
// Health check endpoint
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.String(200, "OK")
|
||||
})
|
||||
|
||||
// Register auth routes
|
||||
routes.RegisterAuthRoutes(r, db)
|
||||
|
||||
// Start server
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
r.Run(":" + port)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue