Documentation
¶
Index ¶
- Constants
- Variables
- func BearerToken(token string) api.Middleware
- func Cache(mode Mode, ttl time.Duration, store GetSetter) api.Middleware
- func ErrorOnStatusCodes(statusCodes ...StatusCodeRange) api.Middleware
- func Header(name, value string) api.Middleware
- func InRanges(code int, ranges []StatusCodeRange) bool
- func JSONHeaders(next api.Dofn) api.Dofn
- func MockResponse(mock func(req *http.Request) (statusCode int, respBody string)) api.Dofn
- func NewMock(mock api.Dofn) api.Middleware
- func NewMockResponse(mock func(req *http.Request) (statusCode int, respBody string)) api.Middleware
- func RetryOnStatusCodes(retry uint, statusCodes ...StatusCodeRange) api.Middleware
- func RetryWithDelay(retry uint, delayMin, delayMax time.Duration, delayRamp float32, ...) api.Middleware
- type ErrMaxRetries
- type ErrStatusCode
- type GetSetter
- type Mode
- type StatusCodeRange
Constants ¶
const ( ModeDefault = iota ModeCacheOnly )
Variables ¶
var Non2XXStatusCodes = StatusCodeRange{Low: 300, High: 599}
Non2XXStatusCodes is the status code range representing non 2XX status codes
Functions ¶
func BearerToken ¶
func BearerToken(token string) api.Middleware
func ErrorOnStatusCodes ¶
func ErrorOnStatusCodes(statusCodes ...StatusCodeRange) api.Middleware
ErrorOnStatusCodes will return an error on certain status codes
func Header ¶
func Header(name, value string) api.Middleware
Header will set the header name and value
func InRanges ¶
func InRanges(code int, ranges []StatusCodeRange) bool
InRanges checks to see if the status code is in the ranges
func JSONHeaders ¶
JSONPayload is a Do func middleware that sets the JSON payload headers
func MockResponse ¶
MockResponse mocks a response object and can be used with NewMock.
func NewMock ¶
func NewMock(mock api.Dofn) api.Middleware
NewMock mocks the Do func and doesn't call in to the next Dofn in line.
func NewMockResponse ¶
NewMockResponse is a convenience func that combines NewMock and MockResponse
func RetryOnStatusCodes ¶
func RetryOnStatusCodes(retry uint, statusCodes ...StatusCodeRange) api.Middleware
RetryOnStatusCodes is a Do func middleware that will retry based on status codes
func RetryWithDelay ¶
func RetryWithDelay(retry uint, delayMin, delayMax time.Duration, delayRamp float32, ranges ...StatusCodeRange) api.Middleware
RetryWithDelay is a Do func middleware that will retry based on status codes or on err. It also can take a delay min, max, and backoff multiplier. If no range is passed, it defaults to Non2XXStatusCodes range
Types ¶
type ErrMaxRetries ¶
type ErrMaxRetries struct {
Err error // the wrapped error
}
ErrMaxRetries is the error that represents when the max number of retries has been reached
func (ErrMaxRetries) Error ¶
func (e ErrMaxRetries) Error() string
Error implements the error interface
func (ErrMaxRetries) Unwrap ¶
func (e ErrMaxRetries) Unwrap() error
type ErrStatusCode ¶
ErrStatusCode This is used when you want to handle a certain status code as an error.
func (ErrStatusCode) Error ¶
func (esc ErrStatusCode) Error() string
type GetSetter ¶
type GetSetter interface {
Get(key string) (io.ReadCloser, error)
Set(key string, ttl time.Duration, body io.ReadCloser) error
}
type StatusCodeRange ¶
StatusCodeRange is a range of status codes
func (StatusCodeRange) InRange ¶
func (scr StatusCodeRange) InRange(code int) bool
InRange checks a status code to see if it is in the range