|
|
|
@ -25,7 +25,7 @@ type (
|
|
|
|
|
Acceptable func(err error) bool
|
|
|
|
|
|
|
|
|
|
Breaker interface {
|
|
|
|
|
// Name returns the name of the netflixBreaker.
|
|
|
|
|
// Name returns the name of the Breaker.
|
|
|
|
|
Name() string
|
|
|
|
|
|
|
|
|
|
// Allow checks if the request is allowed.
|
|
|
|
@ -34,34 +34,34 @@ type (
|
|
|
|
|
// If not allow, ErrServiceUnavailable will be returned.
|
|
|
|
|
Allow() (Promise, error)
|
|
|
|
|
|
|
|
|
|
// Do runs the given request if the netflixBreaker accepts it.
|
|
|
|
|
// Do returns an error instantly if the netflixBreaker rejects the request.
|
|
|
|
|
// If a panic occurs in the request, the netflixBreaker handles it as an 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 netflixBreaker accepts it.
|
|
|
|
|
// DoWithAcceptable returns an error instantly if the netflixBreaker rejects the request.
|
|
|
|
|
// If a panic occurs in the request, the netflixBreaker handles it as an 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 netflixBreaker accepts it.
|
|
|
|
|
// DoWithFallback runs the fallback if the netflixBreaker rejects the request.
|
|
|
|
|
// If a panic occurs in the request, the netflixBreaker handles it as an 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 netflixBreaker accepts it.
|
|
|
|
|
// DoWithFallbackAcceptable runs the fallback if the netflixBreaker rejects the request.
|
|
|
|
|
// If a panic occurs in the request, the netflixBreaker handles it as an 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BreakerOption func(breaker *circuitBreaker)
|
|
|
|
|
Option func(breaker *circuitBreaker)
|
|
|
|
|
|
|
|
|
|
Promise interface {
|
|
|
|
|
Accept()
|
|
|
|
@ -89,7 +89,7 @@ type (
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NewBreaker(opts ...BreakerOption) Breaker {
|
|
|
|
|
func NewBreaker(opts ...Option) Breaker {
|
|
|
|
|
var b circuitBreaker
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
|
opt(&b)
|
|
|
|
@ -127,7 +127,7 @@ func (cb *circuitBreaker) Name() string {
|
|
|
|
|
return cb.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithName(name string) BreakerOption {
|
|
|
|
|
func WithName(name string) Option {
|
|
|
|
|
return func(b *circuitBreaker) {
|
|
|
|
|
b.name = name
|
|
|
|
|
}
|
|
|
|
|