refactor: centralize constants and reorganize documentation
- Create internal/constants package with all hardcoded values (environment, cookies, themes, headers, routes, cache) - Create internal/httputil package for HTTP helper functions - Update all handlers and middleware to use centralized constants - Reorganize documentation with numbered prefixes (00-26) - Remove duplicate docs from validation folder and docs/ - Delete handlers/constants.go (moved to internal/constants)
This commit is contained in:
@@ -4,6 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/juanatsap/cv-site/internal/constants"
|
||||
"github.com/juanatsap/cv-site/internal/httputil"
|
||||
)
|
||||
|
||||
// CmdKAction represents a single action for the ninja-keys command palette
|
||||
@@ -25,14 +28,7 @@ type CmdKResponse struct {
|
||||
// This endpoint provides dynamic entries for experiences, projects, and courses
|
||||
// that can be searched via CMD+K
|
||||
func (h *CVHandler) CmdKData(w http.ResponseWriter, r *http.Request) {
|
||||
// Get language from query parameter, default to "en"
|
||||
lang := r.URL.Query().Get("lang")
|
||||
if lang == "" {
|
||||
lang = "en"
|
||||
}
|
||||
if lang != "en" && lang != "es" {
|
||||
lang = "en"
|
||||
}
|
||||
lang := httputil.Lang(r)
|
||||
|
||||
// Get CV data from cache
|
||||
cv := h.dataCache.GetCV(lang)
|
||||
@@ -93,8 +89,8 @@ func (h *CVHandler) CmdKData(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Set headers and encode response
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600") // Cache for 1 hour
|
||||
w.Header().Set(constants.HeaderContentType, constants.ContentTypeJSON)
|
||||
w.Header().Set(constants.HeaderCacheControl, constants.CachePublic1Hour)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
log.Printf("ERROR encoding CMD+K response: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user