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 httpdriver.Request) error
- func MultipartRequest(r httpdriver.Request) error
- func ResponseNoop(httpdriver.Request, httpdriver.Response) error
- type Client
- func (c *Client) FastRequest(method, url string, opts ...RequestOption) error
- func (c *Client) MeanwhileMultipart(writer func(*multipart.Writer) error, method, url string, ...) (httpdriver.Response, error)
- func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.Response, error)
- func (c *Client) RequestCtx(ctx context.Context, method, url string, opts ...RequestOption) (httpdriver.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
- func PrependOptions(opts []RequestOption, prepend ...RequestOption) []RequestOption
- func WithBody(body io.ReadCloser) RequestOption
- func WithContentType(ctype string) RequestOption
- func WithHeaders(headers http.Header) RequestOption
- func WithJSONBody(json json.Driver, v interface{}) RequestOption
- func WithSchema(schema SchemaEncoder, v interface{}) RequestOption
- type SchemaEncoder
Constants ¶
This section is empty.
Variables ¶
View Source
var Retries uint = 5
Retries is the default attempts to retry if the API returns an error before giving up. If the value is smaller than 1, then requests will retry forever.
Functions ¶
func JSONRequest ¶
func JSONRequest(r httpdriver.Request) error
func MultipartRequest ¶
func MultipartRequest(r httpdriver.Request) error
func ResponseNoop ¶ added in v0.4.0
func ResponseNoop(httpdriver.Request, httpdriver.Response) error
ResponseNoop is used for (*Client).OnResponse.
Types ¶
type Client ¶
type Client struct { httpdriver.Client json.Driver SchemaEncoder // DefaultOptions, if not nil, will be copied and prefixed on each Request. DefaultOptions []RequestOption // OnResponse is called after every Do() call. Response might be nil if Do() // errors out. The error returned will override Do's if it's not nil. OnResponse func(httpdriver.Request, httpdriver.Response) error // Default to the global Retries variable (5). Retries uint }
func (*Client) FastRequest ¶
func (c *Client) FastRequest(method, url string, opts ...RequestOption) error
func (*Client) MeanwhileMultipart ¶
func (c *Client) MeanwhileMultipart( writer func(*multipart.Writer) error, method, url string, opts ...RequestOption) (httpdriver.Response, error)
func (*Client) Request ¶
func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.Response, error)
func (*Client) RequestCtx ¶
func (c *Client) RequestCtx( ctx context.Context, method, url string, opts ...RequestOption) (httpdriver.Response, error)
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 ¶
type RequestOption func(httpdriver.Request) error
func PrependOptions ¶ added in v0.4.0
func PrependOptions(opts []RequestOption, prepend ...RequestOption) []RequestOption
func WithBody ¶
func WithBody(body io.ReadCloser) RequestOption
func WithContentType ¶
func WithContentType(ctype string) RequestOption
func WithHeaders ¶ added in v0.3.2
func WithHeaders(headers http.Header) RequestOption
func WithJSONBody ¶
func WithJSONBody(json json.Driver, v interface{}) RequestOption
WithJSONBody inserts a JSON body into the request. This ignores JSON errors.
func WithSchema ¶
func WithSchema(schema SchemaEncoder, v interface{}) RequestOption
type SchemaEncoder ¶
SchemaEncoder expects the encoder to read the "schema" tags.
Directories ¶
Path | Synopsis |
---|---|
Package httpdriver provides interfaces and implementations of a simple HTTP client.
|
Package httpdriver provides interfaces and implementations of a simple HTTP client. |
Click to show internal directories.
Click to hide internal directories.