go-zero/core/breaker/nopbreaker.go

66 lines
1.3 KiB
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package breaker
import "context"
const nopBreakerName = "nopBreaker"
2020-07-26 17:09:05 +08:00
type nopBreaker struct{}
2020-07-26 17:09:05 +08:00
// NopBreaker returns a breaker that never trigger breaker circuit.
func NopBreaker() Breaker {
return nopBreaker{}
2020-07-26 17:09:05 +08:00
}
func (b nopBreaker) Name() string {
return nopBreakerName
2020-07-26 17:09:05 +08:00
}
func (b nopBreaker) Allow() (Promise, error) {
2020-07-26 17:09:05 +08:00
return nopPromise{}, nil
}
func (b nopBreaker) AllowCtx(_ context.Context) (Promise, error) {
return nopPromise{}, nil
}
func (b nopBreaker) Do(req func() error) error {
2020-07-26 17:09:05 +08:00
return req()
}
func (b nopBreaker) DoCtx(_ context.Context, req func() error) error {
return req()
}
func (b nopBreaker) DoWithAcceptable(req func() error, _ Acceptable) error {
2020-07-26 17:09:05 +08:00
return req()
}
func (b nopBreaker) DoWithAcceptableCtx(_ context.Context, req func() error, _ Acceptable) error {
return req()
}
func (b nopBreaker) DoWithFallback(req func() error, _ Fallback) error {
2020-07-26 17:09:05 +08:00
return req()
}
func (b nopBreaker) DoWithFallbackCtx(_ context.Context, req func() error, _ Fallback) error {
return req()
}
func (b nopBreaker) DoWithFallbackAcceptable(req func() error, _ Fallback, _ Acceptable) error {
2020-07-26 17:09:05 +08:00
return req()
}
func (b nopBreaker) DoWithFallbackAcceptableCtx(_ context.Context, req func() error,
_ Fallback, _ Acceptable) error {
return req()
}
2020-07-26 17:09:05 +08:00
type nopPromise struct{}
func (p nopPromise) Accept() {
}
func (p nopPromise) Reject(_ string) {
2020-07-26 17:09:05 +08:00
}