cb

package
v2.3.55 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyRequests = errors.New("too many requests")
	ErrOpenState       = errors.New("circuit breaker is open")
)

Functions

This section is empty.

Types

type CircuitBreaker

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

func NewCircuitBreaker

func NewCircuitBreaker(name string, st Settings) *CircuitBreaker

func (*CircuitBreaker) Counts

func (cb *CircuitBreaker) Counts() Counts

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(req func() error, opts ...Option) (err error)

func (*CircuitBreaker) Name

func (cb *CircuitBreaker) Name() string

func (*CircuitBreaker) State

func (cb *CircuitBreaker) State() State

type Counts

type Counts struct {
	Requests             uint32
	TotalSuccesses       uint32
	TotalFailures        uint32
	ConsecutiveSuccesses uint32
	ConsecutiveFailures  uint32
}

type Option

type Option func(ops *options)

func Fallback

func Fallback(fallback func(err error) error) Option

func IsSuccessful

func IsSuccessful(isSuccessful func(err error) (success bool)) Option

type Settings

type Settings struct {
	MaxRequests   uint32
	Interval      time.Duration
	Timeout       time.Duration
	ReadyToTrip   func(counts Counts) bool
	OnStateChange func(name string, from State, to State)
	IsSuccessful  func(err error) bool
}

type State

type State int
const (
	StateClosed State = iota
	StateHalfOpen
	StateOpen
)

func (State) String

func (s State) String() string

type TwoStepCircuitBreaker

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

func NewTwoStepCircuitBreaker

func NewTwoStepCircuitBreaker(name string, st Settings) *TwoStepCircuitBreaker

func (*TwoStepCircuitBreaker) Allow

func (cbTs *TwoStepCircuitBreaker) Allow() (done func(success bool), err error)

func (*TwoStepCircuitBreaker) Counts

func (cbTs *TwoStepCircuitBreaker) Counts() Counts

func (*TwoStepCircuitBreaker) Name

func (cbTs *TwoStepCircuitBreaker) Name() string

func (*TwoStepCircuitBreaker) State

func (cbTs *TwoStepCircuitBreaker) State() State

Jump to

Keyboard shortcuts

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