Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCircuitOpen is returned by AllowRequest when the upstream provider // has tripped the failure threshold and is currently blocking requests. ErrCircuitOpen = errors.New("circuit breaker is open (provider overloaded)") )
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker implements the circuit breaker pattern for a single provider.
func NewBreaker ¶
func NewBreaker(cfg *config.CircuitBreakerConfig) *Breaker
NewBreaker creates a new circuit breaker with the given performance configuration.
func (*Breaker) AllowRequest ¶
AllowRequest checks if a request should be allowed to proceed. If the circuit is open, it returns ErrCircuitOpen. In HalfOpen state, it allows up to config.HalfOpenMax requests through to probe the upstream.
func (*Breaker) RecordFailure ¶
func (cb *Breaker) RecordFailure()
RecordFailure records a failed request. It increments the failure counter if closed, or instantly re-opens the circuit if half-open.
func (*Breaker) RecordSuccess ¶
func (cb *Breaker) RecordSuccess()
RecordSuccess records a successful request. It resets the failure counter if closed, or completes the transition to closed if half-open.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages a thread-safe map of Breakers per provider.
func NewRegistry ¶
func NewRegistry(cfg *config.CircuitBreakerConfig) *Registry
NewRegistry creates a new global provider Breaker registry.