bucket

package
v1.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iface

type Iface interface {
	Key(c *gin.Context) string                      // 获取对应的限流器的键值对名称。
	GetBucket(key string) (*ratelimit.Bucket, bool) // 获取对应的限流器的键值对名称。
	AddBuckets(rules ...Rule) Iface                 // 新增多个令牌桶规则。
}

type Limier

type Limier struct {
	// contains filtered or unexported fields
}

Limier 存储令牌桶与键值对名称的映射关系

type PrefixLimiter

type PrefixLimiter struct {
	*Limier
	*PrefixTree
}

func NewPrefixLimiter

func NewPrefixLimiter() *PrefixLimiter

func (*PrefixLimiter) AddBuckets

func (p *PrefixLimiter) AddBuckets(rules ...Rule) Iface

func (*PrefixLimiter) GetBucket

func (p *PrefixLimiter) GetBucket(key string) (*ratelimit.Bucket, bool)

func (*PrefixLimiter) Key

func (p *PrefixLimiter) Key(c *gin.Context) string

type PrefixTree

type PrefixTree struct {
	// contains filtered or unexported fields
}

func NewPrefixTree

func NewPrefixTree() *PrefixTree

func (*PrefixTree) Get

func (t *PrefixTree) Get(prefix []string) interface{}

func (*PrefixTree) Put

func (t *PrefixTree) Put(prefix []string, v interface{})

type Rule

type Rule struct {
	Key          string        // 自定义键值对名称
	FillInterval time.Duration // 增加新桶的间隔时间
	Cap          int64         // 桶的最大容量
	Quantum      int64         // 每次到达间隔时间之后存放的桶数量
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL