Documentation ¶
Overview ¶
Package httpclient provides a retrying circuit-breaked http.Client.
Index ¶
- Constants
- func New(name string) *retryablehttp.Client
- func NewRequest(method, URL string, body interface{}) (*retryablehttp.Request, error)
- func NewWithClient(name string, cl *http.Client, timeout, interval time.Duration, ...) *retryablehttp.Client
- type Breaker
- type GoBreaker
- type TransportWithBreaker
Constants ¶
const ( DefaultTimeout = 10 * time.Second DefaultInterval = 10 * time.Minute DefaultFailureRatio = 0.6 )
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(name string) *retryablehttp.Client
New returns a *retryablehttp.Client, with the default http.Client, DefaultTimeout, DefaultInterval and DefaultFailureRatio.
func NewRequest ¶
NewRequest calls github.com/hashicorp/go-retryablehttp's NewRequest.
func NewWithClient ¶
func NewWithClient(name string, cl *http.Client, timeout, interval time.Duration, failureRatio float64, logger *slog.Logger) *retryablehttp.Client
NewWithClient returns a *retryablehttp.Client based on the given *http.Client. The accompanying circuit breaker is set with the given timeout and interval.
If failureRatio is < 0, then no circuit breaker will be used, if failureRatio == 0, then DefaultFailureRation will be used.
Types ¶
type Breaker ¶
type Breaker interface { // Execute runs the given request if the circuit breaker is closed or half-open states. // An error is instantly returned when the circuit breaker is tripped. Execute(fn func() (interface{}, error)) (interface{}, error) // Opened reports whether the breaker is opened at the moment. Opened() bool }
Breaker is the interface for a circuit breaker.
type GoBreaker ¶
type GoBreaker struct {
*gobreaker.CircuitBreaker
}
GoBreaker adapts a *gobreaker.CircuitBreaker to the Breaker interface.
type TransportWithBreaker ¶
type TransportWithBreaker struct { Tripper http.RoundTripper Breaker Breaker }
TransportWithBreaker shrink-wraps a http.RoundTripper with a circuit Breaker.