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 MultiPolicy ¶ added in v1.4.1
type MultiPolicy struct { TimeoutDuration time.Duration LimitRefreshPeriod time.Duration LimitForPeriod []int }
MultiPolicy defines the policy of a rate limiter
func NewMultiPolicy ¶ added in v1.4.1
func NewMultiPolicy(timeout, refresh time.Duration, limit []int) *MultiPolicy
NewMultiPolicy create and initialize a policy
type MultiRateLimiter ¶ added in v1.4.1
type MultiRateLimiter struct {
// contains filtered or unexported fields
}
MultiRateLimiter defines a rate limiter
func NewMulti ¶ added in v1.4.1
func NewMulti(policy *MultiPolicy) *MultiRateLimiter
NewMulti creates a multi rate limiter based on `policy`,
func (*MultiRateLimiter) AcquirePermission ¶ added in v1.4.1
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 (*MultiRateLimiter) SetState ¶ added in v1.4.1
func (rl *MultiRateLimiter) SetState(state State)
SetState sets the state of the rate limiter to `state`
func (*MultiRateLimiter) WaitPermission ¶ added in v1.4.1
func (rl *MultiRateLimiter) WaitPermission(counts []int) (bool, error)
WaitPermission waits a permission from the rate limiter returns true if the request is permitted and false if timed out
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) AcquireNPermission ¶ added in v1.4.1
func (rl *RateLimiter) AcquireNPermission(n int) (bool, time.Duration)
AcquireNPermission acquires N 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) 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