limiter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCounter

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

func (*GCounter) Limit

func (c *GCounter) Limit(n int64) (allow bool, err error)

Limit 限流,GCounter计数限流器限流

增加allow计数,在limitTime时间内计数达到limitThreshold阈值则触发限流,limitTime时间后会重置

type GLimiter

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

func NewGLimiter

func NewGLimiter(redisOper RedisLimiterOperate, opts ...Option) GLimiter

func (*GLimiter) GetGCounter

func (g *GLimiter) GetGCounter(key string, limitThreshold int64, limitTime time.Duration) *GCounter

GetCounter GCounter, 获取key的计数限流器GCounter

limitTime时间内计数达到limitThreshold阈值则触发限流,limitTime时间后会重置

type GLimiterOptions

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

type Option

type Option func(opts *GLimiterOptions)

func WithLogger

func WithLogger(logger log.FieldsLogger) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithUnPrefix

func WithUnPrefix() Option

type RedisLimiterOperate

type RedisLimiterOperate interface {
	IncrBy(key string, increment int64) (int64, error)
	PExpire(key string, millisecond time.Duration) (int64, error)
	PTTL(key string) (int64, error)
}

Jump to

Keyboard shortcuts

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