1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
package api import ( "encoding/json" "net/http" ) type errorResponse struct { Error string `json:"error"` } func writeError( w http.ResponseWriter, status int, message string, ) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) _ = json.NewEncoder(w).Encode(errorResponse{ Error: message, }) }