initial boilerplate

This commit is contained in:
2026-05-03 16:43:53 +03:00
parent bea266e066
commit 2e63e0e95b
18 changed files with 1878 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
package handlers
import (
"encoding/json"
"net/http"
)
// writeJSON encodes v as JSON and writes it to w with the given status code.
// This is a tiny helper that every handler uses — it keeps handlers clean.
func writeJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(v); err != nil {
http.Error(w, "encoding error", http.StatusInternalServerError)
}
}
// writeError writes a standard {"error": "..."} JSON response.
func writeError(w http.ResponseWriter, status int, msg string) {
writeJSON(w, status, map[string]string{"error": msg})
}