feat: simplify architecture by removing cache layer and centralizing routes

- Removed over-engineered cache system for static CV data that only changes on deployment
- Extracted all route configuration to internal/routes/routes.go for better organization
- Implemented rate limiting and cache control middleware for PDF endpoint protection
This commit is contained in:
juanatsap
2025-11-12 17:53:24 +00:00
parent 927d257f2c
commit 211fd05462
18 changed files with 967 additions and 3042 deletions
+3 -26
View File
@@ -5,24 +5,13 @@ import (
"log"
"net/http"
"time"
"github.com/juanatsap/cv-site/internal/models"
)
// HealthResponse represents the health check response
type HealthResponse struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
Version string `json:"version"`
Cache *CacheInfo `json:"cache,omitempty"`
}
// CacheInfo represents cache statistics
type CacheInfo struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Size int `json:"size"`
HitRate float64 `json:"hit_rate_percent"`
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
Version string `json:"version"`
}
// HealthHandler handles health check requests
@@ -45,21 +34,9 @@ func (h *HealthHandler) Check(w http.ResponseWriter, r *http.Request) {
Version: h.version,
}
// Include cache stats if available
if cache := models.GetCache(); cache != nil {
stats := cache.GetStats()
response.Cache = &CacheInfo{
Hits: stats.Hits,
Misses: stats.Misses,
Size: stats.Size,
HitRate: cache.HitRate(),
}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(response); err != nil {
// Log error but don't change response status (already written)
log.Printf("ERROR encoding health check response: %v", err)
}
}