Automated Action 887703b6a2 Add Go Todo App implementation
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
2025-05-17 22:20:05 +00:00

41 lines
953 B
Go

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/simpletodoapp/go-todo-app/internal/database"
"github.com/simpletodoapp/go-todo-app/internal/dto"
)
// HealthHandler handles health check requests
type HealthHandler struct {
db *database.Database
}
// NewHealthHandler creates a new health check handler
func NewHealthHandler(db *database.Database) *HealthHandler {
return &HealthHandler{db: db}
}
// RegisterRoutes registers the health check routes
func (h *HealthHandler) RegisterRoutes(router *gin.Engine) {
router.GET("/health", h.HealthCheck)
}
// HealthCheck handles GET /health
// Returns the health status of the application
func (h *HealthHandler) HealthCheck(c *gin.Context) {
// Check database health
dbStatus := "healthy"
if err := h.db.Health(); err != nil {
dbStatus = "unhealthy"
}
response := dto.HealthResponse{
Status: "healthy",
DBStatus: dbStatus,
}
c.JSON(http.StatusOK, response)
}