circuit

package
v0.5.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (cb *Breaker) AllowRequest() error

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.

func (*Breaker) State

func (cb *Breaker) State() State

State returns the current state of the circuit breaker.

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.

func (*Registry) Get

func (r *Registry) Get(provider string) *Breaker

Get returns the circuit breaker for the given provider, creating it implicitly if missing.

type State

type State int

State represents the circuit breaker state.

const (
	StateClosed State = iota
	StateOpen
	StateHalfOpen
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL