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:
juanatsap
2025-12-06 16:27:12 +00:00
parent 71d9258c58
commit 2c7f8de242
37 changed files with 732 additions and 343 deletions
+6 -4
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"log"
"net/http"
"github.com/juanatsap/cv-site/internal/constants"
)
// ErrorResponse represents a structured error response
@@ -62,12 +64,12 @@ func HandleError(w http.ResponseWriter, r *http.Request, err error) {
// Determine response based on Accept header
accept := r.Header.Get("Accept")
isJSON := accept == "application/json"
isHTMX := r.Header.Get("HX-Request") != ""
isJSON := accept == constants.ContentTypeJSON
isHTMX := r.Header.Get(constants.HeaderHXRequest) != ""
if isJSON {
// JSON response
w.Header().Set("Content-Type", "application/json")
w.Header().Set(constants.HeaderContentType, constants.ContentTypeJSON)
w.WriteHeader(appErr.StatusCode)
response := ErrorResponse{
@@ -88,7 +90,7 @@ func HandleError(w http.ResponseWriter, r *http.Request, err error) {
if isHTMX {
// HTMX response - return simple HTML fragment
w.Header().Set("Content-Type", "text/html")
w.Header().Set(constants.HeaderContentType, constants.ContentTypeHTMLFragment)
w.WriteHeader(appErr.StatusCode)
message := appErr.Message