Documentation
¶
Index ¶
- Variables
- func WithIsFailure(isFailure func(err error) bool) option
- func WithMaxFailures(maxFailures uint) option
- func WithMaxHalfOpenRequests(maxRequests uint) option
- func WithNow(now func() time.Time) option
- func WithTimeout(timeout time.Duration) option
- type Breaker
- type Registry
- type State
- type Status
Constants ¶
This section is empty.
Variables ¶
var ErrBreakerOpen = errors.New("circuit breaker is open")
ErrBreakerOpen indicates that the breaker is in the open state and will not run the supplied callback. This error will also be returned in the half open state and at capacity.
Functions ¶
func WithIsFailure ¶
WithIsFailure defines the logic for determining if the error should be counted toward the breaker failures.
func WithMaxFailures ¶
func WithMaxFailures(maxFailures uint) option
WithMaxFailures indicates the breaker should go into the open state after reaching the supplied number of consecutive failures.
func WithMaxHalfOpenRequests ¶
func WithMaxHalfOpenRequests(maxRequests uint) option
WithMaxRequests set the maximum number of requests that should be made while in the half open state.
func WithNow ¶
WithNow sets the function for getting the current time. This is only useful for testing.
func WithTimeout ¶
WithTimeout sets the duration over which the breaker will remain in the open state.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker provides the logic for conditionally calling a function based on its passed performance.
type Registry ¶
Registry stores circuit breakers by name. This is useful because a circuit breaker must be re-used for each call of the same type and the registry provides a mechanism for retrieving that circuit breaker.
type State ¶
type State struct { // The number of consecutive failures. This is only tracked when the // circuit breaker is in the closed state. Failures uint // The number of consecutive successes. This is only tracked when // the circuit breaker is in the half open state. Successes uint // contains filtered or unexported fields }
State maintains the state of the circuit breaker, which includes the status and relevant counts.
type Status ¶
type Status uint8
const ( // Closed indicates the callback function will be run as normal. Closed Status = 0 // HalfOpen indicates the callback function will be run in a limited // capacity and a failure will return it to the open state. HalfOpen Status = 1 // Open indicates the callback function will not be run while in // this state. Open Status = 2 )