Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //ErrCircuitOpen is returned on function calls during Open Circuit State ErrCircuitOpen = errors.New("circuit open") )
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action func() (interface{}, error)
Action is the signature used inside Execute function that runs the circuitBreaker.
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker is the main struct of the project
func New ¶
func New(opts CircuitBreakerOpts) *CircuitBreaker
New initiate a new CircuitBreaker Object.
func (*CircuitBreaker) Execute ¶
func (cb *CircuitBreaker) Execute(ctx context.Context, fn Action) (interface{}, error)
Execute executes the user defined function in the circuit breaker
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() State
GetState returns current state of the circuit breaker. 0 -> Open, 1 -> Half, 2 -> Closed
type CircuitBreakerOpts ¶
type CircuitBreakerOpts struct {
// Number of errors past which the circuit breaker will open
Threshold uint
//
// value from 1 to 99. When HsThresholdPercentage of good requests is reached in half state , circuit is closed
// any input below 1 will be set to 1 and value above 99 will be set to 99
HsThresholdPercentage uint
// Function passed with this signature will be called whenever a state is changed.
NotifyFunc func(s int)
//Sleep time after which OpenCircuit switches to Half-Open.
Duration time.Duration
}
CircuitBreakerOpts is the option Configuration struct
Click to show internal directories.
Click to hide internal directories.