Documentation ¶
Index ¶
Constants ¶
View Source
const ( // Unknown 未知状态码 Unknown = 0 // Allowed 小于配额状态码 Allowed = 1 // Reached 达到配额状态码 Reached = 2 // Overflowed 超出配额状态码 Overflowed = 3 // InvalidQuota 无效配额 InvalidQuota = -1 )
Variables ¶
View Source
var ( // ErrUnknownCode 未知状态码错误 ErrUnknownCode = stderrors.New("unknown code") // ErrUnexpectedType 意外类型错误 ErrUnexpectedType = stderrors.New("unexpected type") )
Functions ¶
This section is empty.
Types ¶
type PeriodLimit ¶
type PeriodLimit struct {
// contains filtered or unexported fields
}
PeriodLimit 时间段限流器
func MustNewPeriodLimit ¶
func MustNewPeriodLimit(period, quota int, keyPrefix string, store *xkv.Store) *PeriodLimit
MustNewPeriodLimit 新建时间段限流器
func NewPeriodLimit ¶
NewPeriodLimit 新建时间段限流器
func (*PeriodLimit) Allow ¶
func (pl *PeriodLimit) Allow(key string, opts ...Option) (bool, error)
Allow 访问时间段限流器拿取配额,并判断是否允许放行
type TokenLimit ¶
type TokenLimit struct {
// contains filtered or unexported fields
}
TokenLimit 令牌桶限流器
func MustNewTokenLimit ¶
func MustNewTokenLimit(rate, capacity int, key string, store *xkv.Store) *TokenLimit
MustNewTokenLimit 新建令牌桶限流器
func NewTokenLimit ¶
NewTokenLimit 新建令牌桶限流器
func (*TokenLimit) Allow ¶
func (tl *TokenLimit) Allow(opts ...TokenOption) (bool, error)
Allow 访问令牌桶限流器拿取令牌,并判断是否允许拿取
func (*TokenLimit) AllowN ¶
func (tl *TokenLimit) AllowN(now time.Time, n int, opts ...TokenOption) (bool, error)
AllowN 访问令牌桶限流器拿取 n 个令牌,并判断是否允许拿取
Click to show internal directories.
Click to hide internal directories.