limit

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CombinationLimit

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

CombinationLimit 组合限流器

func NewCombinationLimit

func NewCombinationLimit(limits ...Limit) *CombinationLimit

NewCombinationLimit 创建组合限流器

func (*CombinationLimit) FuncTake

func (c *CombinationLimit) FuncTake(ctx context.Context, key string, f func() (interface{}, error)) (interface{}, error)

func (*CombinationLimit) Take

func (c *CombinationLimit) Take(ctx context.Context, key string) (func() error, error)

type Empty added in v1.1.0

type Empty struct {
}

func (*Empty) FuncTake added in v1.1.0

func (e *Empty) FuncTake(ctx context.Context, key string, f func() (interface{}, error)) (interface{}, error)

func (*Empty) Take added in v1.1.0

func (e *Empty) Take(ctx context.Context, key string) (func() error, error)

type Limit

type Limit interface {
	Take(ctx context.Context, key string) (func() error, error)
	FuncTake(ctx context.Context, key string, f func() (interface{}, error)) (interface{}, error)
}

func NewEmpty added in v1.1.0

func NewEmpty() Limit

NewEmpty 创建空限流器

type PeriodLimit

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

PeriodLimit 周期限流器,redis zet实现滑动窗口

func NewPeriodLimit

func NewPeriodLimit(period, quota int64, limitStore *redis.Client, keyPrefix string) *PeriodLimit

NewPeriodLimit 创建周期限流器,period单位秒,quota限流数量

func (*PeriodLimit) Count

func (p *PeriodLimit) Count(ctx context.Context, key string, period int64) (int64, error)

Count 获取用量

func (*PeriodLimit) FuncTake

func (p *PeriodLimit) FuncTake(ctx context.Context, key string, f func() (interface{}, error)) (interface{}, error)

func (*PeriodLimit) Take

func (p *PeriodLimit) Take(ctx context.Context, key string) (func() error, error)

Jump to

Keyboard shortcuts

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