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