ratelimiter

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRate = 2147483647
)
View Source
const (
	RATELIMITER = "RATELIMITER"
)

Variables

View Source
var (
	ErrLimiterRegisterAdapterNil    = fmt.Errorf("Limiter: Register adapter is nil")
	ErrLimiterDoubleRegisterAdapter = fmt.Errorf("Limiter: Register called twice for adapter")
)

Functions

func HasRegister

func HasRegister(name string) bool

func Register

func Register(name string, adapter Instance)

Types

type Instance

type Instance func() Limiter

func GetDefaultLimiter

func GetDefaultLimiter() Instance

func GetLimiter

func GetLimiter(name string) (Instance, bool)

type Limiter

type Limiter interface {
	TryAccept(name string, qps, burst int) bool // Accept请求, limiter接受正常返回,不接受返回false

	UpdateRateLimit(name string, qps, burst int) // 更新qps, 并发burst接口,etcd配置变化
	DeleteRateLimiter(name string)               // 清理 limiter
	// contains filtered or unexported methods
}

func NewRateLimiters

func NewRateLimiters() Limiter

type RateLimiters

type RateLimiters struct {
	sync.RWMutex // 协程 安全
	// contains filtered or unexported fields
}

func (*RateLimiters) DeleteRateLimiter

func (l *RateLimiters) DeleteRateLimiter(name string)

func (*RateLimiters) TryAccept

func (l *RateLimiters) TryAccept(name string, qps, burst int) bool

func (*RateLimiters) UpdateRateLimit

func (l *RateLimiters) UpdateRateLimit(name string, qps, burst int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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