package api import ( "encoding/json" "log" "net/http" ) // writeJSON writes v as a JSON response with the given status code. func writeJSON(w http.ResponseWriter, status int, v any) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) if v == nil { return } if err := json.NewEncoder(w).Encode(v); err != nil { log.Printf("writeJSON: %v", err) } } // errorBody is the standard error envelope. type errorBody struct { Error string `json:"error"` } // writeError writes a JSON error response. func writeError(w http.ResponseWriter, status int, msg string) { writeJSON(w, status, errorBody{Error: msg}) }