Documentation ¶
Index ¶
- Variables
- func GetLimiterType() (res []string)
- type ConcurrentLimit
- func (limiter *ConcurrentLimit) GetSpeed() int64
- func (limiter *ConcurrentLimit) GetTimeout() time.Duration
- func (limiter *ConcurrentLimit) GetVolumn() int
- func (limiter *ConcurrentLimit) SetRate(volume int, _ int64)
- func (limiter *ConcurrentLimit) SetTimeout(timeout time.Duration)
- func (limiter *ConcurrentLimit) Take() error
- func (limiter *ConcurrentLimit) TakeWithTimeout() error
- type LimiterType
- type QpsRateLimiter
- func (r *QpsRateLimiter) GetSpeed() int64
- func (r *QpsRateLimiter) GetTimeout() time.Duration
- func (r *QpsRateLimiter) GetVolumn() int
- func (r *QpsRateLimiter) SetRate(init int, speed int64)
- func (r *QpsRateLimiter) SetTimeout(time time.Duration)
- func (r *QpsRateLimiter) Take() error
- func (r *QpsRateLimiter) TakeWithTimeout(timeout time.Duration) error
- type RateLimiter
- type RateLimiterFactory
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GetLimiterType ¶
func GetLimiterType() (res []string)
Types ¶
type ConcurrentLimit ¶
func (*ConcurrentLimit) GetSpeed ¶
func (limiter *ConcurrentLimit) GetSpeed() int64
func (*ConcurrentLimit) GetTimeout ¶
func (limiter *ConcurrentLimit) GetTimeout() time.Duration
func (*ConcurrentLimit) GetVolumn ¶
func (limiter *ConcurrentLimit) GetVolumn() int
func (*ConcurrentLimit) SetRate ¶
func (limiter *ConcurrentLimit) SetRate(volume int, _ int64)
func (*ConcurrentLimit) SetTimeout ¶
func (limiter *ConcurrentLimit) SetTimeout(timeout time.Duration)
func (*ConcurrentLimit) Take ¶
func (limiter *ConcurrentLimit) Take() error
func (*ConcurrentLimit) TakeWithTimeout ¶
func (limiter *ConcurrentLimit) TakeWithTimeout() error
type LimiterType ¶
type LimiterType string
type QpsRateLimiter ¶
func (*QpsRateLimiter) GetSpeed ¶
func (r *QpsRateLimiter) GetSpeed() int64
func (*QpsRateLimiter) GetVolumn ¶
func (r *QpsRateLimiter) GetVolumn() int
func (*QpsRateLimiter) SetRate ¶
func (r *QpsRateLimiter) SetRate(init int, speed int64)
init:初始化的个数 speed:一秒生成多少个 token
func (*QpsRateLimiter) SetTimeout ¶
func (r *QpsRateLimiter) SetTimeout(time time.Duration)
func (*QpsRateLimiter) Take ¶
func (r *QpsRateLimiter) Take() error
func (*QpsRateLimiter) TakeWithTimeout ¶
func (r *QpsRateLimiter) TakeWithTimeout(timeout time.Duration) error
type RateLimiter ¶
type RateLimiter interface { Take() error TakeWithTimeout(time.Duration) error SetRate(int, int64) // 设置速率 GetVolumn() int GetSpeed() int64 GetTimeout() time.Duration SetTimeout(time.Duration) }
* 限流器在整个程序内部中会被频繁创建,由此采用工厂设计模式
func Build ¶
func Build(t LimiterType) (RateLimiter, error)
func NewQpsRateLimiter ¶
func NewQpsRateLimiter() RateLimiter
type RateLimiterFactory ¶
type RateLimiterFactory func() RateLimiter
Click to show internal directories.
Click to hide internal directories.