Documentation ¶
Index ¶
- Constants
- Variables
- type BadStatusError
- type Client
- func (c *Client) Delete(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string, v interface{}) (*Response, error)
- func (c *Client) Patch(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
- func (c *Client) Post(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
- func (c *Client) Put(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
- func (c *Client) Send(request *Request) *Future
- type ContentTypeError
- type DecodeHook
- type Decoder
- type DecoderJSON
- type Doer
- type Encoder
- type EncoderFormURL
- type EncoderJSON
- type Future
- type InvalidMethodError
- type Option
- type Request
- type Response
Constants ¶
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the default time limit for requests made by the client.
Variables ¶
var DefaultStatusValidator = func(status int) bool {
return status >= 200 && status < 300
}
DefaultStatusValidator returns true for 2xx statuses, otherwise false.
Functions ¶
This section is empty.
Types ¶
type BadStatusError ¶
type BadStatusError int
BadStatusError is returned if the client's status validator function returns false.
func (BadStatusError) Error ¶
func (statusCode BadStatusError) Error() string
Error implements the error interface
type Client ¶
type Client struct { BaseURL string DefaultEncoder Encoder StatusValidator func(int) bool BaseClient Doer }
Client is an HTTP client that uses the BaseClient to send requests
func New ¶
New returns a new Client with sensible defaults. The defaults can be overridden by supplying Options.
func NewFromBaseClient ¶
NewFromBaseClient returns a new Client that wraps BaseClient
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
Delete performs a DELETE request
func (*Client) Patch ¶
func (c *Client) Patch(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
Patch performs a PATCH request
func (*Client) Post ¶
func (c *Client) Post(ctx context.Context, url string, body interface{}, v interface{}) (*Response, error)
Post performs a POST request
type ContentTypeError ¶
type ContentTypeError string
ContentTypeError is returned if the response has a Content-Type header that cannot be handled by one of the built-in decoders and neither the client nor request have a default decoder set.
func (ContentTypeError) Error ¶
func (contentType ContentTypeError) Error() string
Error implements the error interface
type DecodeHook ¶
type DecodeHook func(status int) interface{}
func On2xx ¶
func On2xx(v interface{}) DecodeHook
func On4xx ¶
func On4xx(v interface{}) DecodeHook
func On5xx ¶
func On5xx(v interface{}) DecodeHook
func OnNon2xx ¶
func OnNon2xx(v interface{}) DecodeHook
func OnStatus ¶
func OnStatus(status int, v interface{}) DecodeHook
type DecoderJSON ¶
type DecoderJSON struct{}
DecoderJSON decodes JSON bodies
func (*DecoderJSON) Decode ¶
func (d *DecoderJSON) Decode(data []byte, v interface{}) error
Decode unmarshals a JSON response body
type Doer ¶
Doer executes HTTP requests. It is implemented by http.Client{}. You can wrap an http.Client{} in a custom Doer implementation to create middleware.
type EncoderFormURL ¶
type EncoderFormURL struct { // CustomContentType overrides the default ContentType // of application/x-www-form-urlencoded CustomContentType string // TagAlias is the tag to read on struct fields. // If empty, "form" will be used. TagAlias string }
EncoderFormURL encodes bodies as x-www-form-urlencoded
func (EncoderFormURL) ContentType ¶
func (e EncoderFormURL) ContentType() string
ContentType returns the ContentType header to set in an outbound request
type EncoderJSON ¶
type EncoderJSON struct { // CustomContentType overrides the default ContentType // of application/json; charset=utf-8 CustomContentType string }
EncoderJSON encodes bodies as JSON
func (EncoderJSON) ContentType ¶
func (e EncoderJSON) ContentType() string
ContentType returns the ContentType header to set in an outbound request
type Future ¶
type Future struct {
// contains filtered or unexported fields
}
Future represents an in-flight request
type InvalidMethodError ¶
type InvalidMethodError string
InvalidMethodError is returned if an unsupported HTTP method is specified
func (InvalidMethodError) Error ¶
func (method InvalidMethodError) Error() string
Error implements the error interface
type Option ¶
type Option func(c *Client)
func WithBaseURL ¶
func WithEncoder ¶
func WithStatusValidator ¶
func WithTimeout ¶
type Request ¶
type Request struct { Ctx context.Context Method string URL string Headers http.Header Body interface{} Encoder Encoder }
Request holds the information needed to make an HTTP request
type Response ¶
Response represents the response from a request
func (*Response) BodyString ¶
BodyString returns the body as a string
func (*Response) DecodeJSON ¶
func (*Response) DecodeUsing ¶
DecodeUsing decodes the response into the receivers using the given Decoder