Documentation ¶
Index ¶
- Variables
- func Do(name string, req func() error) error
- func DoWithAcceptable(name string, req func() error, acceptable Acceptable) error
- func DoWithFallback(name string, req func() error, fallback func(err error) error) error
- func DoWithFallbackAcceptable(name string, req func() error, fallback func(err error) error, ...) error
- func NoBreakerFor(name string)
- type Acceptable
- type Breaker
- type Option
- type Promise
Constants ¶
This section is empty.
Variables ¶
ErrServiceUnavailable is returned when the Breaker state is open.
Functions ¶
func DoWithAcceptable ¶
func DoWithAcceptable(name string, req func() error, acceptable Acceptable) error
DoWithAcceptable calls Breaker.DoWithAcceptable on the Breaker with given name.
func DoWithFallback ¶
DoWithFallback calls Breaker.DoWithFallback on the Breaker with given name.
func DoWithFallbackAcceptable ¶
func DoWithFallbackAcceptable(name string, req func() error, fallback func(err error) error, acceptable Acceptable) error
DoWithFallbackAcceptable calls Breaker.DoWithFallbackAcceptable on the Breaker with given name.
func NoBreakerFor ¶
func NoBreakerFor(name string)
NoBreakerFor disables the circuit breaker for the given name.
Types ¶
type Acceptable ¶
Acceptable is the func to check if the error can be accepted.
type Breaker ¶
type Breaker interface { // Name returns the name of the Breaker. Name() string // Allow checks if the request is allowed. // If allowed, a promise will be returned, the caller needs to call promise.Accept() // on success, or call promise.Reject() on failure. // If not allow, ErrServiceUnavailable will be returned. Allow() (Promise, error) // Do runs the given request if the Breaker accepts it. // Do returns an error instantly if the Breaker rejects the request. // If a panic occurs in the request, the Breaker handles it as an error // and causes the same panic again. Do(req func() error) error // DoWithAcceptable runs the given request if the Breaker accepts it. // DoWithAcceptable returns an error instantly if the Breaker rejects the request. // If a panic occurs in the request, the Breaker handles it as an error // and causes the same panic again. // acceptable checks if it's a successful call, even if the err is not nil. DoWithAcceptable(req func() error, acceptable Acceptable) error // DoWithFallback runs the given request if the Breaker accepts it. // DoWithFallback runs the fallback if the Breaker rejects the request. // If a panic occurs in the request, the Breaker handles it as an error // and causes the same panic again. DoWithFallback(req func() error, fallback func(err error) error) error // DoWithFallbackAcceptable runs the given request if the Breaker accepts it. // DoWithFallbackAcceptable runs the fallback if the Breaker rejects the request. // If a panic occurs in the request, the Breaker handles it as an error // and causes the same panic again. // acceptable checks if it's a successful call, even if the err is not nil. DoWithFallbackAcceptable(req func() error, fallback func(err error) error, acceptable Acceptable) error }
A Breaker represents a circuit breaker.
func GetBreaker ¶
GetBreaker returns the Breaker with the given name.
func NewBreaker ¶
NewBreaker returns a Breaker object. opts can be used to customize the Breaker.
Click to show internal directories.
Click to hide internal directories.