Documentation
¶
Overview ¶
Package circuit provides circuit breaker pattern implementation for high availability.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCircuitOpen = errors.New("circuit breaker is open") ErrTooManyRequests = errors.New("too many requests in half-open state") )
Errors
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker implements the circuit breaker pattern.
func NewBreaker ¶
NewBreaker creates a new circuit breaker with the given configuration.
func (*Breaker) Allow ¶
Allow checks if a request should be allowed through. Returns an error if the circuit is open.
func (*Breaker) ForceOpen ¶
func (b *Breaker) ForceOpen()
ForceOpen forces the circuit breaker to open state.
func (*Breaker) RecordFailure ¶
func (b *Breaker) RecordFailure()
RecordFailure records a failed operation.
func (*Breaker) RecordSuccess ¶
func (b *Breaker) RecordSuccess()
RecordSuccess records a successful operation.
type Config ¶
type Config struct {
// FailureThreshold is the number of failures before opening the circuit.
// Default: 5
FailureThreshold int
// SuccessThreshold is the number of successes before closing the circuit.
// Default: 3
SuccessThreshold int
// Timeout is how long to wait before attempting recovery.
// Default: 30 seconds
Timeout time.Duration
// MaxRequests is the maximum requests allowed in half-open state.
// Default: 1
MaxRequests int
// OnStateChange is called when the state changes.
OnStateChange func(from, to State)
}
Config holds circuit breaker configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple circuit breakers.
func NewManager ¶
NewManager creates a new circuit breaker manager.
Click to show internal directories.
Click to hide internal directories.