Documentation
¶
Overview ¶
Package circuit implements the Circuit Breaker pattern for http client. It will wrap a http request and monitor for failures and/or time outs. When a threshold of failures or time outs has been reached, future requests will not run. During this state, the breaker will allow limited number of http requests to run and, if they are successful, will start performing all http requests again.
Index ¶
- Constants
- func DefaultReadyToTrip(counts gobreaker.Counts) bool
- type Breaker
- type ClientOption
- type GoBreaker
- type GoBreakerOnStateChangeFunc
- type GoBreakerOption
- func WithGoBreakerInterval(interval time.Duration) GoBreakerOption
- func WithGoBreakerMaxRequests(maxRequests uint32) GoBreakerOption
- func WithGoBreakerName(name string) GoBreakerOption
- func WithGoBreakerOnStateChange(onStateChange GoBreakerOnStateChangeFunc) GoBreakerOption
- func WithGoBreakerReadyToTrip(readyToTrip GoBreakerReadyToTripFunc) GoBreakerOption
- func WithGoBreakerTimeout(timeout time.Duration) GoBreakerOption
- type GoBreakerReadyToTripFunc
- type HTTPClient
- type HTTPRequestDoer
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func DefaultReadyToTrip ¶
Types ¶
type ClientOption ¶
type ClientOption func(*HTTPClient)
func WithCircuitBreaker ¶
func WithCircuitBreaker(cb Breaker) ClientOption
func WithHTTPRequestDoer ¶
func WithHTTPRequestDoer(client HTTPRequestDoer) ClientOption
type GoBreaker ¶
type GoBreaker struct {
// contains filtered or unexported fields
}
func NewGoBreaker ¶
func NewGoBreaker(opts ...GoBreakerOption) *GoBreaker
type GoBreakerOption ¶
type GoBreakerOption func(*GoBreaker)
func WithGoBreakerInterval ¶
func WithGoBreakerInterval(interval time.Duration) GoBreakerOption
WithGoBreakerInterval sets the cyclic period of the closed state for CircuitBreaker to clear the internal Counts, described in gobreaker documentation. If Interval is 0, CircuitBreaker doesn't clear the internal Counts during the closed state. Default value is 2 minutes.
func WithGoBreakerMaxRequests ¶
func WithGoBreakerMaxRequests(maxRequests uint32) GoBreakerOption
WithGoBreakerMaxRequests sets the maximum number of requests allowed to pass through when the CircuitBreaker is half-open. If MaxRequests is 0, CircuitBreaker allows only 1 request. Default value is 50 requests.
func WithGoBreakerName ¶
func WithGoBreakerName(name string) GoBreakerOption
WithGoBreakerName sets the name of the CircuitBreaker. Default value is "GoBreaker".
func WithGoBreakerOnStateChange ¶
func WithGoBreakerOnStateChange(onStateChange GoBreakerOnStateChangeFunc) GoBreakerOption
WithGoBreakerOnStateChange sets the function that is called whenever the state of CircuitBreaker changes.
func WithGoBreakerReadyToTrip ¶
func WithGoBreakerReadyToTrip(readyToTrip GoBreakerReadyToTripFunc) GoBreakerOption
WithGoBreakerReadyToTrip sets the function that is called with a copy of Counts whenever a request fails in the closed state. If ReadyToTrip returns true, CircuitBreaker will be placed into the open state. If ReadyToTrip is nil, default ReadyToTrip is used. Default ReadyToTrip returns true when number of requests more than 100 and the percent of failures is more than 50 percents.
func WithGoBreakerTimeout ¶
func WithGoBreakerTimeout(timeout time.Duration) GoBreakerOption
WithGoBreakerTimeout sets the period of the open state, after which the state of CircuitBreaker becomes half-open. If Timeout is 0, the timeout value of CircuitBreaker is set to 60 seconds. Default value is 1 minute.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
func NewHTTPClient ¶
func NewHTTPClient(opts ...ClientOption) *HTTPClient