Documentation
¶
Overview ¶
Package breakerpool provides a generic circuit breaker pool with priority-based failover.
Index ¶
Constants ¶
const DefaultPriority = 100
DefaultPriority is the default priority for entries without an explicit priority.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllUnavailableError ¶
type AllUnavailableError struct {
}
AllUnavailableError indicates all endpoints are unavailable.
func (*AllUnavailableError) Error ¶
func (e *AllUnavailableError) Error() string
func (*AllUnavailableError) Unwrap ¶
func (e *AllUnavailableError) Unwrap() error
type Entry ¶
type Entry[S any] struct { // State is passed to the Execute callback. This is the only required field. State S // Priority determines failover order. Higher values are tried first. // If zero, DefaultPriority (100) is used. Priority int // Settings overrides the pool's default gobreaker settings for this entry. // If nil, the pool's default settings are used. Settings *gobreaker.Settings }
Entry associates state with optional per-entry circuit breaker settings.
type Pool ¶
type Pool[T, S any] struct { // contains filtered or unexported fields }
Pool manages circuit breakers with priority-based failover. When executing operations, it tries entries in priority order (highest first), using round-robin within the same priority tier. If a breaker is open or trips, the pool tries the next available entry.
func New ¶
New creates a new Pool with the given entries and default circuit breaker settings. For each entry:
- Uses entry.Settings if non-nil, otherwise uses defaults
- Uses entry.Priority if non-zero, otherwise uses DefaultPriority
func (*Pool[T, S]) AllUnavailable ¶
AllUnavailable returns true if all circuit breakers are in the open state.
func (*Pool[T, S]) Execute ¶
Execute runs the given function against entries in priority order. The function receives the entry's State and should perform the operation. If the operation fails with an error that trips the circuit breaker, Execute tries the next available entry. Returns AllUnavailableError if all entries are unavailable.