Documentation
¶
Index ¶
- Variables
- func BuildURLWithQuery(url string, qs map[string]string) (string, error)
- func DefaultHTTPClient() *http.Client
- func DefaultHTTPTransport() *http.Transport
- type Client
- func (c *Client) Delete(ctx context.Context, url string) (*Response, error)
- func (c *Client) Do(req *http.Request) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string) (*Response, error)
- func (c *Client) NewRequest(ctx context.Context, method string, url string, body io.Reader) (*http.Request, error)
- func (c *Client) OverrideURL(url string)
- func (c *Client) Patch(ctx context.Context, url string, body io.Reader) (*Response, error)
- func (c *Client) Post(ctx context.Context, url string, body io.Reader) (*Response, error)
- func (c *Client) Put(ctx context.Context, url string, body io.Reader) (*Response, error)
- type Option
- func WithAccept(s string) Option
- func WithAfterRequest(f func(resp *Response) error) Option
- func WithAuth(s string) Option
- func WithAuthBearer(s string) Option
- func WithBaseURL(s string) Option
- func WithBeforeRequest(f func(req *http.Request) error) Option
- func WithContentType(s string) Option
- func WithDebugRequest(l zerolog.Logger) Option
- func WithDebugResponse(l zerolog.Logger) Option
- func WithFormatErrors(b bool) Option
- func WithHTTPClient(client *http.Client) Option
- func WithHeaders(m map[string]string) Option
- type Response
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
func BuildURLWithQuery ¶
BuildURLWithQuery build a URL with query strings.
func DefaultHTTPClient ¶
DefaultHTTPClient returns a http.Client with sane defaults. It should be used as a starting point instead of an empty http.Client.
func DefaultHTTPTransport ¶
DefaultHTTPTransport returns a http.Transport with sane defaults. It should be used as a starting point instead of an empty http.Transport.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) NewRequest ¶
func (c *Client) NewRequest(ctx context.Context, method string, url string, body io.Reader) (*http.Request, error)
NewRequest creates a new HTTP request.
func (*Client) OverrideURL ¶
OverrideURL overrides the request's URL. Mostly for testing and using with httptest.Server.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithAccept ¶
WithAccept sets the Accept header that will be sent with all request.
func WithAfterRequest ¶
WithAfterRequest sets a function that will run after every request and has access to the current response to inspect and/or modify it. Can be called multiple times to chain functions.
func WithAuthBearer ¶
WithAuthBearer sets the Authorization header with the Bearer prefix that will be sent with all requests.
func WithBaseURL ¶
WithBaseURL sets a base URL that will be prepended to every subsequent URL when making requests.
func WithBeforeRequest ¶
WithBeforeRequest sets a function that will run before every request and has access to the current request to inspect and/or modify it. Can be called multiple times to chain functions.
func WithContentType ¶
WithContentType sets the ContentType header that will be sent with POST, PUT and PATCH requests.
func WithDebugRequest ¶
WithDebugRequest will log the request to the supplied zerolog.Logger.
func WithDebugResponse ¶
WithDebugResponse will log the response to the supplied zerolog.Logger.
func WithFormatErrors ¶
WithFormatErrors will format the >= 400 responses and return them in the following format: 'http.client: <status_code> response for <url>: <body>'. 404 responses will return ErrNotFound instead as sometimes a 404 is expected.
func WithHTTPClient ¶
WithHTTPClient sets the http.Client.
func WithHeaders ¶
WithHeaders sets headers that will be sent with all requests.