reliability

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCircuitOpen is returned when the circuit breaker is open.
	ErrCircuitOpen = errors.New("circuit breaker is open")
)

Functions

This section is empty.

Types

type Breaker

type Breaker interface {
	// Allow checks if the request is allowed to proceed.
	Allow() bool

	// Success reports a successful execution.
	Success()

	// Failure reports a failed execution.
	Failure()
}

Breaker defines the interface for a circuit breaker.

type CircuitBreakerDriver

type CircuitBreakerDriver struct {
	cache.Driver
	// contains filtered or unexported fields
}

CircuitBreakerDriver wraps a cache driver with a circuit breaker.

func NewCircuitBreakerDriver

func NewCircuitBreakerDriver(driver cache.Driver, breaker Breaker) *CircuitBreakerDriver

NewCircuitBreakerDriver creates a new CircuitBreakerDriver.

func (*CircuitBreakerDriver) Flush

func (d *CircuitBreakerDriver) Flush(ctx context.Context) error

func (*CircuitBreakerDriver) Forget

func (d *CircuitBreakerDriver) Forget(ctx context.Context, key string) error

func (*CircuitBreakerDriver) Get

func (d *CircuitBreakerDriver) Get(ctx context.Context, key string) (interface{}, error)

func (*CircuitBreakerDriver) Put

func (d *CircuitBreakerDriver) Put(ctx context.Context, key string, value interface{}, ttl time.Duration) error

type State

type State int

State represents the state of the circuit breaker.

const (
	StateClosed State = iota
	StateOpen
	StateHalfOpen
)

type ThresholdBreaker

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

ThresholdBreaker implements a simple failure threshold circuit breaker.

func NewThresholdBreaker

func NewThresholdBreaker(threshold int, timeout time.Duration) *ThresholdBreaker

NewThresholdBreaker creates a new ThresholdBreaker.

func (*ThresholdBreaker) Allow

func (b *ThresholdBreaker) Allow() bool

Allow checks if the request is allowed.

func (*ThresholdBreaker) Failure

func (b *ThresholdBreaker) Failure()

Failure reports a failure.

func (*ThresholdBreaker) Success

func (b *ThresholdBreaker) Success()

Success reports a success.

Jump to

Keyboard shortcuts

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