Documentation ¶
Index ¶
- func DefaultErrorCheck(r *Request, doErr error, res *http.Response) error
- func DefaultErrorSummary(body []byte) string
- func DefaultRequestPrepare(*Request) error
- func DefaultResponseHandle(r *Request, res *http.Response) error
- func Do(ctx context.Context, method, urlStr string, opts ...RequestOption) (*http.Request, *http.Response, error)
- type ErrorCheck
- type ErrorSummary
- type Request
- type RequestOption
- func DontClose() RequestOption
- func RecvJSON(recvs interface{}) RequestOption
- func RecvText(recvs *string) RequestOption
- func RecvXML(recvs interface{}) RequestOption
- func SendJSON(sends interface{}) RequestOption
- func SendText(sends string) RequestOption
- func SendXML(sends interface{}) RequestOption
- type RequestPrepare
- type ResponseHandle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorCheck ¶
DefaultErrorCheck is the default error checker used if none is configured on a Request. doErr and res are the return values of executing http.Client.Do(), so any implementation should first check doErr for non-nill & react appropriately. If an http response was received, if a non-200 class status was also received, then the response body will be read (up to a const limit) and passed to request.ErrorSummary to attempt to parse out the error body, which will be passed as the "detail" flag on the returned error.
func DefaultErrorSummary ¶
DefaultErrorSummary just returns the string of the received error body. Note that the body passed in is potentially truncated before this call.
func DefaultRequestPrepare ¶
DefaultRequestPrepare does nothing.
func DefaultResponseHandle ¶
DefaultResponseHandle merely closes the response body.
Types ¶
type ErrorCheck ¶
ErrorCheck is the signature for the function that is passed the error & response immediately from http.Client.Do().
type ErrorSummary ¶
ErrorSummary is the signature for the function that is passed the fully read body of an error response.
type Request ¶
type Request struct { *http.Request Client *http.Client ErrorCheck ErrorCheck ErrorBodyMaxLength int64 ErrorSummary ErrorSummary ResponseHandle ResponseHandle RequestPrepare RequestPrepare }
Request encompasses an http.Request, plus configured behavior options.
func New ¶
New creates and returns a new Request, potentially configured via a vector of RequestOption's.
func (*Request) Do ¶
Do executes the Request. The Request.ErrorCheck to determine if this attempt has failed, and transform the returned error. Otherwise, Request.ResponseHandler will examine the response. It's expected that the ResponseHandler has been configured via a RequestOption to perform response parsing and storing.
func (*Request) ErrorFields ¶
ErrorFields returns error annotation fields for the request.
type RequestOption ¶
type RequestOption func(*Request)
RequestOption is the signature for functions that can perform some configuration of a Request.
func DontClose ¶
func DontClose() RequestOption
DontClose sets the ResponseBody to an empty function, so that the response body is not automatically closed. Users of this should be sure to call res.Body.Close().
func RecvJSON ¶
func RecvJSON(recvs interface{}) RequestOption
RecvJSON returns a RequestOption that will set the json headers on a request, and set a ResponseHandler that will unmarshal the response body to the given interface{}.
func RecvText ¶
func RecvText(recvs *string) RequestOption
RecvText returns a RequestOption that will set the text headers on a request, and set a ResponseHandler that will unmarshal the response body to the given string.
func RecvXML ¶
func RecvXML(recvs interface{}) RequestOption
RecvXML returns a RequestOption that will set the xml headers on a request, and set a ResponseHandler that will unmarshal the response body to the given interface{}.
func SendJSON ¶
func SendJSON(sends interface{}) RequestOption
SendJSON returns a RequestOption that will marshal and set the json body & headers on a request.
func SendText ¶
func SendText(sends string) RequestOption
SendText returns a RequestOption that will marshal and set the text body & headers on a request.
func SendXML ¶
func SendXML(sends interface{}) RequestOption
SendXML returns a RequestOption that will marshal and set the xml body & headers on a request.
type RequestPrepare ¶
RequestPrepare is the signature for the function called before calling http.Client.Do, to perform any preparation needed before executing the request, eg. marshaling the body.