package api import ( "encoding/json" "net/http" ) func writeJSON(w http.ResponseWriter, status int, v any) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) _ = json.NewEncoder(w).Encode(v) } func writeErr(w http.ResponseWriter, status int, msg string) { writeJSON(w, status, map[string]string{"error": msg}) } func readJSON(r *http.Request, dst any) error { defer r.Body.Close() dec := json.NewDecoder(r.Body) dec.DisallowUnknownFields() return dec.Decode(dst) }