package main import ( "encoding/json" "net/http" ) type errorHTTPResponse struct { ErrorMsg string HTTPStatusCode int HTTPHeader http.Header } func (e errorHTTPResponse) Error() string { return e.ErrorMsg } func errorHTTPResponseNew(r *http.Response, msg string) (e errorHTTPResponse) { e.ErrorMsg = msg e.HTTPStatusCode = r.StatusCode e.HTTPHeader = r.Header return e } type crmdReason struct { Reason string `json:"reason"` Data string `json:"data"` } func (e *errorHTTPResponse) XStatusReason() (r crmdReason) { jsonStr := e.HTTPHeader.Get("X-Status-Reason") json.Unmarshal([]byte(jsonStr), &r) return }