Documentation ¶
Index ¶
Constants ¶
const ( StateNormal = iota StateLimiting StateDisabled )
circuit breaker states
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventListenerFunc ¶
type EventListenerFunc func(event *Event)
EventListenerFunc is a listener function to listen state transit event
type Policy ¶
type Policy struct { TimeoutDuration time.Duration LimitRefreshPeriod time.Duration LimitForPeriod int }
Policy defines the policy of a rate limiter
func NewDefaultPolicy ¶ added in v1.2.0
func NewDefaultPolicy() *Policy
NewDefaultPolicy create and initialize a policy with default configuration
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter defines a rate limiter
func (*RateLimiter) AcquirePermission ¶
func (rl *RateLimiter) AcquirePermission() (bool, time.Duration)
AcquirePermission acquires a permission from the rate limiter. returns true if the request is permitted and false otherwise. when permitted, the caller should wait returned duration before action.
func (*RateLimiter) SetState ¶
func (rl *RateLimiter) SetState(state State)
SetState sets the state of the rate limiter to `state`
func (*RateLimiter) SetStateListener ¶
func (rl *RateLimiter) SetStateListener(listener EventListenerFunc)
SetStateListener sets a state listener for the RateLimiter
func (*RateLimiter) WaitPermission ¶
func (rl *RateLimiter) WaitPermission() bool
WaitPermission waits a permission from the rate limiter returns true if the request is permitted and false if timed out