circuit

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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