Documentation ¶
Overview ¶
Package httputil provides abstractions around the common needs of HTTP. It also allows swapping in and out the HTTP client.
Index ¶
- Variables
- func JSONRequest(r *http.Request) error
- func MultipartRequest(r *http.Request) error
- type Client
- func (c *Client) FastRequest(method, url string, opts ...RequestOption) error
- func (c *Client) MeanwhileMultipart(multipartWriter func(*multipart.Writer) error, method, url string, ...) (*http.Response, error)
- func (c *Client) Request(method, url string, opts ...RequestOption) (*http.Response, error)
- func (c *Client) RequestCtx(ctx context.Context, method, url string, opts ...RequestOption) (*http.Response, error)
- func (c *Client) RequestCtxJSON(ctx context.Context, to interface{}, method, url string, opts ...RequestOption) error
- func (c *Client) RequestJSON(to interface{}, method, url string, opts ...RequestOption) error
- type DefaultSchema
- type ErrorCode
- type HTTPError
- type JSONError
- type RequestError
- type RequestOption
- type SchemaEncoder
- type TransportWrapper
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = NewClient()
View Source
var Retries uint = 5
Retries is the default attempts to retry if the API returns an error before giving up.
Functions ¶
func JSONRequest ¶
func MultipartRequest ¶
Types ¶
type Client ¶
func (*Client) FastRequest ¶
func (c *Client) FastRequest( method, url string, opts ...RequestOption) error
func (*Client) MeanwhileMultipart ¶
func (*Client) RequestCtx ¶
func (*Client) RequestCtxJSON ¶
func (*Client) RequestJSON ¶
func (c *Client) RequestJSON( to interface{}, method, url string, opts ...RequestOption) error
type DefaultSchema ¶
type HTTPError ¶
type RequestError ¶
type RequestError struct {
// contains filtered or unexported fields
}
type RequestOption ¶
func WithBody ¶
func WithBody(body io.ReadCloser) RequestOption
func WithContentType ¶
func WithContentType(ctype string) RequestOption
func WithJSONBody ¶
func WithJSONBody(json json.Driver, v interface{}) RequestOption
func WithSchema ¶
func WithSchema(schema SchemaEncoder, v interface{}) RequestOption
type SchemaEncoder ¶
SchemaEncoder expects the encoder to read the "schema" tags.
type TransportWrapper ¶
type TransportWrapper struct { Default http.RoundTripper Pre func(*http.Request) error Cancel func(*http.Request, error) Post func(*http.Response) error }
func NewTransportWrapper ¶
func NewTransportWrapper() *TransportWrapper
Click to show internal directories.
Click to hide internal directories.