|
|
|
@ -7,24 +7,28 @@ var (
|
|
|
|
|
breakers = make(map[string]Breaker)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Do calls Breaker.Do on the Breaker with given name.
|
|
|
|
|
func Do(name string, req func() error) error {
|
|
|
|
|
return do(name, func(b Breaker) error {
|
|
|
|
|
return b.Do(req)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DoWithAcceptable calls Breaker.DoWithAcceptable on the Breaker with given name.
|
|
|
|
|
func DoWithAcceptable(name string, req func() error, acceptable Acceptable) error {
|
|
|
|
|
return do(name, func(b Breaker) error {
|
|
|
|
|
return b.DoWithAcceptable(req, acceptable)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DoWithFallback calls Breaker.DoWithFallback on the Breaker with given name.
|
|
|
|
|
func DoWithFallback(name string, req func() error, fallback func(err error) error) error {
|
|
|
|
|
return do(name, func(b Breaker) error {
|
|
|
|
|
return b.DoWithFallback(req, fallback)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DoWithFallbackAcceptable calls Breaker.DoWithFallbackAcceptable on the Breaker with given name.
|
|
|
|
|
func DoWithFallbackAcceptable(name string, req func() error, fallback func(err error) error,
|
|
|
|
|
acceptable Acceptable) error {
|
|
|
|
|
return do(name, func(b Breaker) error {
|
|
|
|
@ -32,6 +36,7 @@ func DoWithFallbackAcceptable(name string, req func() error, fallback func(err e
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetBreaker returns the Breaker with the given name.
|
|
|
|
|
func GetBreaker(name string) Breaker {
|
|
|
|
|
lock.RLock()
|
|
|
|
|
b, ok := breakers[name]
|
|
|
|
@ -51,7 +56,8 @@ func GetBreaker(name string) Breaker {
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NoBreakFor(name string) {
|
|
|
|
|
// NoBreakerFor disables the circuit breaker for the given name.
|
|
|
|
|
func NoBreakerFor(name string) {
|
|
|
|
|
lock.Lock()
|
|
|
|
|
breakers[name] = newNoOpBreaker()
|
|
|
|
|
lock.Unlock()
|
|
|
|
|