Documentation ¶
Index ¶
- Variables
- func Download(url string, dest string, options ...Option) (written int64, err error)
- func FormPostRequest(url string, form url.Values) (*http.Request, error)
- func IsNetworkError(e error) bool
- func PerformRequest(request *http.Request, options ...Option) (*http.Response, error)
- func PostRequest(url string, contentType string, body io.Reader) (*http.Request, error)
- type ActionOptions
- type ErrorHandler
- type Option
- type RequestRetrierOptions
- type RetrierOption
- func WithConnectionChecker(checker concheck.Checker) RetrierOption
- func WithConstRetryDelay(delay time.Duration) RetrierOption
- func WithMaxRetries(maxRetries int) RetrierOption
- func WithRetrierContext(ctx context.Context) RetrierOption
- func WithRetryDelay(delay time.Duration, multiplier float64, max time.Duration) RetrierOption
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = http.Client{ Timeout: time.Second * 30, Transport: tr, }
View Source
var ( // ErrRetryRequest is the error reported by Error handler if error is considered insignificant and request might be // re-attempted again. ErrRetryRequest = errors.New("retry request") )
Functions ¶
func Download ¶
Download sends a request to a given URL and writes response body to the destination. It does not account for status codes and will write any body it receives without errors.
It will be removed in the future when the better APIs are available. Avoid using it.
func IsNetworkError ¶
func PerformRequest ¶
Types ¶
type ActionOptions ¶
type ActionOptions struct { // Error handlers defined in sequential order. If error occurs during the execution of an action, then the first // handler is called, if it returns an error that is not ErrRetryRequest, then this error is returned to the // caller of the action. If the error is ErrRetryRequest, then the action is repeated. If no error is returned, // then the next handler is called. If no handlers handle the error, then the error is returned to the caller. ErrorHandlers []ErrorHandler // HTTP client used to execute the action. Client *http.Client }
type ErrorHandler ¶
ErrorHandler handles errors that occur during the execution of an action. It may return an error if it needs a raise, or ErrRetryRequest error, if request can be repeated. If nil is returned, then the next error handler is called.
type Option ¶
type Option func(*http.Request, *ActionOptions)
func WithRetries ¶
func WithRetries(options ...RetrierOption) Option
type RequestRetrierOptions ¶
type RequestRetrierOptions struct { MaxRetries int // Maximum number of retries, 0 means infinite. AllowNonNetworkErrors bool // Whether to allow non-network errors to be retried. RetryDelay time.Duration // Initial delay between retries. It cannot be less than a zero. RetryDelayMultiplier float64 // Multiplier of retry delay for each retry. It cannot be less than one. RetryDelayMax time.Duration // Maximum delay between retries. It cannot be less than RetryDelay. ConnectionChecker concheck.Checker // Network connection checker in case of network error. If nil, then connection is not checked. Context context.Context // Context for the retrier. }
type RetrierOption ¶
type RetrierOption func(*RequestRetrierOptions)
func WithConnectionChecker ¶
func WithConnectionChecker(checker concheck.Checker) RetrierOption
func WithConstRetryDelay ¶
func WithConstRetryDelay(delay time.Duration) RetrierOption
func WithMaxRetries ¶
func WithMaxRetries(maxRetries int) RetrierOption
func WithRetrierContext ¶
func WithRetrierContext(ctx context.Context) RetrierOption
func WithRetryDelay ¶
Click to show internal directories.
Click to hide internal directories.