Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Debug = false
Debug when true will print additional retry details to console
var ErrInvalidClientImpl = errors.New("httpclient: invalid response from Do")
ErrInvalidClientImpl is an error that's returned when the Client Do returns nil to both response and error
var ErrRequestTimeout = errors.New("httpclient: timeout")
ErrRequestTimeout is an error that's returned when the max timeout is reached for a request
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Get(url string) (*http.Response, error)
Post(url string, contentType string, body io.Reader) (*http.Response, error)
Do(req *http.Request) (*http.Response, error)
}
Client is an interface that mimics http.Client
var Default Client = NewHTTPClientDefault()
Default can be used to get a basic implementation of Client interface
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient is an implementation of the Client interface
func NewHTTPClient ¶
func NewHTTPClient(ctx context.Context, config *Config, client Client) *HTTPClient
NewHTTPClient returns a configured HTTPClient instance
func NewHTTPClientDefault ¶
func NewHTTPClientDefault() *HTTPClient
NewHTTPClientDefault returns a default HTTPClient instance
type Paginator ¶
type Paginator interface {
HasMore(page int, req *http.Request, resp *http.Response) (bool, *http.Request)
}
Paginator is an interface for handling request pagination
func InBodyPaginator ¶
func InBodyPaginator() Paginator
InBodyPaginator returns a new paginator that it's pagination info it's inside body
func NewLinkPaginator ¶
func NewLinkPaginator() Paginator
NewLinkPaginator returns a new Paginator that uses the HTTP Link Header for building the next request
func NoPaginator ¶
func NoPaginator() Paginator
NoPaginator returns a no-op paginator that doesn't do pagination
type Retryable ¶
type Retryable interface {
RetryError(err error) bool
RetryResponse(resp *http.Response) bool
RetryDelay(retry int) time.Duration
RetryMaxDuration() time.Duration
}
Retryable is an interface for retrying a request
func NewBackoffRetry ¶
func NewBackoffRetry(initialTimeout time.Duration, incrementingTimeout time.Duration, maxTimeout time.Duration, exponentFactor float64) Retryable
NewBackoffRetry will return a Retryable that will support expotential backoff
func NewNoRetry ¶
func NewNoRetry() Retryable
NewNoRetry will return a struct that implements Retryable but doesn't retry at all