circuitbreaker

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircuitBreaker

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

CircuitBreaker implements the circuit breaker pattern

func New

func New(config Config) *CircuitBreaker

New creates a new circuit breaker

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(ctx context.Context, fn func() error) error

Execute executes the given function with circuit breaker protection

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset resets the circuit breaker to closed state

func (*CircuitBreaker) State

func (cb *CircuitBreaker) State() State

State returns the current state

type Config

type Config struct {
	MaxFailures int
	Timeout     time.Duration
	HalfOpenMax int
}

Config configures the circuit breaker

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration

type State

type State int

State represents the state of the circuit breaker

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