Documentation ¶
Overview ¶
Package httpclient is *http.Client helpers
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNonNilContext = errors.New("web/httpclient: context cannot be nil")
ErrNonNilContext when required context param is nil.
Functions ¶
func LoggerMiddleware ¶
LoggerMiddleware logs request and response of http calls.
func NewStdHTTPClient ¶
NewStdHTTPClient returns golang's default httpClient.
Types ¶
type ContextHTTPClient ¶
type ContextHTTPClient struct {
// contains filtered or unexported fields
}
ContextHTTPClient wrapper of http.Client with required context param.
func NewContextHTTPClient ¶
func NewContextHTTPClient(c *http.Client) *ContextHTTPClient
NewContextHTTPClient returns instance of ContextHTTPClient.
func (*ContextHTTPClient) Do ¶
func (c *ContextHTTPClient) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error hapens, the response is returned as is. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.
The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.
type Option ¶
type Option func(*options)
Option sets options for http client.
func WithMaxConnection ¶
WithMaxConnection returns an Option which sets http client connection pool size default is 50.
func WithTimeout ¶
WithTimeout returns an Option which sets http client's timeout default is 5 seconds.