
This commit adds a complete Go implementation of the Todo application. The application uses Gin framework for the web server, GORM for database access, and SQLite for storage. Key features: - Todo CRUD operations with the same API endpoints - Health check endpoint - Database migrations - Tests for models, services, and API handlers - Documentation for the API - Configurable settings
32 lines
768 B
Go
32 lines
768 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/simpletodoapp/go-todo-app/internal/config"
|
|
"github.com/simpletodoapp/go-todo-app/internal/database"
|
|
"github.com/simpletodoapp/go-todo-app/internal/service"
|
|
)
|
|
|
|
// SetupRouter initializes the API router and routes
|
|
func SetupRouter(cfg *config.Config, db *database.Database) *gin.Engine {
|
|
router := gin.Default()
|
|
|
|
// Setup middleware
|
|
SetupMiddleware(router)
|
|
|
|
// Setup API documentation
|
|
SetupDocs(router, cfg)
|
|
|
|
// Create services
|
|
todoService := service.NewTodoService(db.DB)
|
|
|
|
// Register handlers
|
|
healthHandler := NewHealthHandler(db)
|
|
healthHandler.RegisterRoutes(router)
|
|
|
|
todoHandler := NewTodoHandler(todoService)
|
|
api := router.Group("/api")
|
|
todoHandler.RegisterRoutes(api)
|
|
|
|
return router
|
|
} |