Documentation ¶
Index ¶
Constants ¶
const ( DEFAULT_RETRY_COUNT = 1 DEFAULT_RETRY_BACKOFF = 500 * time.Millisecond DEFAULT_BREAKER_INTERVAL = 10 * time.Second DEFAULT_BREAKER_TIMEOUT = 10 * time.Second DEFAULT_BREAKER_PREFIX_NAME = "default" DEFAULT_BREAKER_MAX_REQUEST = 4 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BreakerSettings ¶
type BreakerSettings struct { Name string `json:"name"` MaxRequests uint32 `json:"max-request"` Interval time.Duration `json:"interval"` Timeout time.Duration `json:"timeout"` ReadyToTrip func(counts gobreaker.Counts) bool `json:"-"` OnStateChange func(name string, from gobreaker.State, to gobreaker.State) `json:"-"` IsSuccessful func(err error) bool `json:"-"` }
Settings configures CircuitBreaker:
Name is the name of the CircuitBreaker.
MaxRequests is the maximum number of requests allowed to pass through when the CircuitBreaker is half-open. If MaxRequests is 0, the CircuitBreaker allows only 1 request.
Interval is the cyclic period of the closed state for the CircuitBreaker to clear the internal Counts. If Interval is less than or equal to 0, the CircuitBreaker doesn't clear internal Counts during the closed state.
Timeout is the period of the open state, after which the state of the CircuitBreaker becomes half-open. If Timeout is less than or equal to 0, the timeout value of the CircuitBreaker is set to 60 seconds.
ReadyToTrip is called with a copy of Counts whenever a request fails in the closed state. If ReadyToTrip returns true, the CircuitBreaker will be placed into the open state. If ReadyToTrip is nil, default ReadyToTrip is used. Default ReadyToTrip returns true when the number of consecutive failures is more than 5.
OnStateChange is called whenever the state of the CircuitBreaker changes.
IsSuccessful is called with the error returned from a request. If IsSuccessful returns true, the error is counted as a success. Otherwise the error is counted as a failure. If IsSuccessful is nil, default IsSuccessful is used, which returns false for all non-nil errors.
type HttpClient ¶
func New ¶
func New(settings *Settings) HttpClient
type RetrySettings ¶
type Settings ¶
type Settings struct { RetrySettings RetrySettings `json:"retrySettings"` BreakerSettings BreakerSettings `json:"breakerSettings"` }