Documentation
¶
Index ¶
- Variables
- type ConfigOpt
- func WithBackoff(backoff RetryBackoff) ConfigOpt
- func WithBackoffDuration(dur time.Duration) ConfigOpt
- func WithDNS(dns dns.DNS) ConfigOpt
- func WithMaxAttempts(max uint) ConfigOpt
- func WithMaxConcurrency(max uint64) ConfigOpt
- func WithRecorder(recorder Recorder) ConfigOpt
- func WithTimeout(timeout time.Duration) ConfigOpt
- type HTTPRequest
- type Http
- type Recorder
- type Request
- type Response
- type RetryBackoff
Constants ¶
This section is empty.
Variables ¶
var ErrTooManyAttempts = errors.New("too many attempts")
Functions ¶
This section is empty.
Types ¶
type ConfigOpt ¶
type ConfigOpt func(opts *configOpts)
func WithBackoff ¶
func WithBackoff(backoff RetryBackoff) ConfigOpt
WithBackoff sets the backoff strategy for the http client.
func WithBackoffDuration ¶
WithBackoffDuration sets the backoff duration for the http client.
func WithMaxAttempts ¶
WithMaxAttempts sets the max number of attempts for the http client.
func WithMaxConcurrency ¶
WithMaxConcurrency sets the max number of concurrent requests.
func WithRecorder ¶
WithRecorder sets the recorder for the http client.
func WithTimeout ¶
WithTimeout sets the timeout for the http client.
type HTTPRequest ¶
type HTTPRequest struct {
// contains filtered or unexported fields
}
func (*HTTPRequest) Headers ¶
func (r *HTTPRequest) Headers() map[string]string
func (*HTTPRequest) Method ¶
func (r *HTTPRequest) Method() string
func (*HTTPRequest) Payload ¶
func (r *HTTPRequest) Payload() []byte
func (*HTTPRequest) URL ¶
func (r *HTTPRequest) URL() string
type Http ¶
type Http interface {
// Deliver sends a request and returns a response.
Deliver(ctx context.Context, request Request) (*Response, error)
}
Http is an interface for making HTTP requests.
type Request ¶
type Request interface {
// Method returns the HTTP method.
Method() string
// URL returns the URL.
URL() string
// Headers returns the headers.
Headers() map[string]string
// Payload returns the payload.
Payload() []byte
}
Request is an interface for an HTTP request.
func NewHTTPGetRequest ¶
NewHTTPGetRequest creates a new HTTPRequest that implements the Request interface for GET requests.
func NewHTTPPostRequest ¶
NewHTTPPostRequest creates a new HTTPRequest that implements the Request interface for POST requests.
type Response ¶
type Response struct {
StatusCode int `json:"statusCode"`
Body []byte `json:"body,omitempty"`
Headers map[string]string `json:"headers"`
Attempts uint `json:"attempts"`
Latency time.Duration `json:"latency"`
}
Response is the response from an HTTP request.
type RetryBackoff ¶
type RetryBackoff interface {
// BackOff returns the duration to wait before retrying.
BackOff(attempt uint) time.Duration
}
RetryBackoff is an interface for retrying a request with a backoff.
func NewMinMaxBackoff ¶
func NewMinMaxBackoff(min time.Duration, max time.Duration) RetryBackoff
NewMinMaxBackoff creates a new RetryBackoff that retries with a backoff of min * 2^attempt.