circuit

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Breaker

type Breaker struct {
	// contains filtered or unexported fields
}

Breaker implements the circuit breaker pattern

func NewBreaker

func NewBreaker(threshold int, timeout time.Duration) *Breaker

NewBreaker creates a new circuit breaker threshold: number of consecutive failures before opening the circuit timeout: duration to wait before transitioning from open to half-open

func (*Breaker) Allow

func (b *Breaker) Allow() bool

Allow returns true if the request is allowed to proceed

func (*Breaker) Failures

func (b *Breaker) Failures() int

Failures returns the current failure count

func (*Breaker) RecordFailure

func (b *Breaker) RecordFailure()

RecordFailure records a failed operation May transition to open state if threshold is exceeded

func (*Breaker) RecordSuccess

func (b *Breaker) RecordSuccess()

RecordSuccess records a successful operation Resets the circuit breaker to closed state

func (*Breaker) Reset

func (b *Breaker) Reset()

Reset resets the circuit breaker to closed state

func (*Breaker) State

func (b *Breaker) State() State

State returns the current state of the circuit breaker

type State

type State int

State represents the circuit breaker state

const (
	StateClosed   State = iota // Normal operation
	StateOpen                  // Circuit breaker is open, requests fail fast
	StateHalfOpen              // Testing if service has recovered
)

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