package api import ( "encoding/json" "net/http" ) func WriteJSON(w http.ResponseWriter, status int, v any) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) return json.NewEncoder(w).Encode(v) } func ReadJSON(r *http.Request, v any) error { return json.NewDecoder(r.Body).Decode(v) } func WriteError(w http.ResponseWriter, status int, message string) { w.WriteHeader(status) json.NewEncoder(w).Encode(map[string]string{"error": message}) }