package server import ( "encoding/json" "net/http" ) type ErrorResponse struct { Error string `json:"error"` Details string `json:"details,omitempty"` } func WriteError(w http.ResponseWriter, error, details string, statusCode int) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(statusCode) json.NewEncoder(w).Encode(ErrorResponse{ Error: error, Details: details, }) }