Documentation ¶
Overview ¶
内部钩子
Index ¶
Constants ¶
View Source
const ( SlowReqRecord = "SlowReqRecord" ReqRecord = "ReqRecord" ErrorReqRecord = "ErrorReqRecord" )
View Source
const CircuitHookKey = "CircuitHook"
Variables ¶
View Source
var ( ErrTooManyRequests = errors.New("too many requests") ErrOpenState = errors.New("circuit breaker is open") )
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
断路器
断路器的状态改变都是延迟懒惰的
func NewCircuitBreaker ¶
func NewCircuitBreaker(st CircuitSettings) *CircuitBreaker
func (*CircuitBreaker) Name ¶
func (cb *CircuitBreaker) Name() string
type CircuitHook ¶
type CircuitHook struct {
// contains filtered or unexported fields
}
断路器钩子
func NewCircuitHook ¶
func NewCircuitHook(settings CircuitSettings) *CircuitHook
func (*CircuitHook) AfterRequest ¶
func (*CircuitHook) BeforeRequest ¶
func (*CircuitHook) SetHandleCErr ¶
func (ch *CircuitHook) SetHandleCErr(handleFunc func(cErr error, req core.Request) error)
type CircuitSettings ¶
type CircuitSettings struct { Name string MaxRequests uint32 Interval time.Duration Timeout time.Duration ReadyToTrip func(counts Counts) bool OnStateChange func(name string, from State, to State) }
Name 名字,请务必保障名字的唯一性
MaxRequests Half-Open状态下允许通过的最大请求数 ¶
Interval 重置时间间隔(Closed状态下有效)。如果为零,永远不重置。
Timeout 超时时间(Open状态下有效)。
超时之后,状态将转变为Half-Open状态。 如果为零,默认为60秒
ReadyToTrip 测试是否应该从Closed状态转变为Open状态。
true 表示可以转变,否则不可以。 如果不配置,则采用默认的。默认失败次数达到5次则进入Open状
OnStateChange 状态变化将调用此方法。
func (*CircuitSettings) Clone ¶
func (set *CircuitSettings) Clone() interface{}
type Counts ¶
type Counts struct { Requests uint32 TotalSuccesses uint32 TotalFailures uint32 ConsecutiveSuccesses uint32 ConsecutiveFailures uint32 }
记录请求的数量以及失败和成功数量
type LogHook ¶
type LogHook struct {
// contains filtered or unexported fields
}
func (*LogHook) AfterRequest ¶
Click to show internal directories.
Click to hide internal directories.