limiter

package
v0.0.0-...-b2b1cb1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

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

type LimiterBucketRule

type LimiterBucketRule struct {
	Key          string        // 自定义键值对名称
	FillInterval time.Duration // 间隔多久时间放 N 个令牌
	Capacity     int64         // 令牌桶的容量
	Quantum      int64         // 每次到达间隔时间后所放的具体令牌数量
}

LimiterBucketRule 用于存储令牌桶的一些相应规则属性

type LimiterIface

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

func NewMethodLimiter

func NewMethodLimiter() LimiterIface

type MethodLimiter

type MethodLimiter struct {
	*Limiter
}

func (MethodLimiter) AddBuckets

func (m MethodLimiter) AddBuckets(rules ...LimiterBucketRule) LimiterIface

func (MethodLimiter) GetBucket

func (m MethodLimiter) GetBucket(key string) (*ratelimit.Bucket, bool)

func (MethodLimiter) Key

func (m MethodLimiter) Key(c *gin.Context) string

Jump to

Keyboard shortcuts

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