limiter

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package limiter

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLimitExceed is returned when the rate limiter is
	// triggered and the request is rejected due to limit exceeded.
	ErrLimitExceed = errors.New("rate limit exceeded")
)

Functions

This section is empty.

Types

type Entry

type Entry interface {
	Allow() bool  // 是否允许
	Finish()      // 结束
	Error() error // 错误信息
}

type Limiter

type Limiter interface {
	// Check 获取一个entry
	Check(ctx context.Context, r Resource) Entry
	// SetLimit 动态地改变 Token 桶大小
	SetLimit(ctx context.Context, r Resource)
	// SetBurst 动态地改变 生成速率
	SetBurst(ctx context.Context, r Resource)
	// SetWindow 动态地改变 滑动窗口
	SetWindow(ctx context.Context, r Resource)
}

type Resource

type Resource struct {
	Name   string        // 限流器名称
	Limit  int           // 每秒事件数
	Burst  int           // 突发令牌数
	Window time.Duration // 滑动窗口时间
}

Directories

Path Synopsis
alone
bbr
Package bbr
Package bbr
leakybucket
Reference uber ratelimit, the different is support no wait take func
Reference uber ratelimit, the different is support no wait take func
slidingwindow
Package slidingwindow is a generated GoMock package.
Package slidingwindow is a generated GoMock package.
distributed
leakybucket
Package leakybucket is a generated GoMock package.
Package leakybucket is a generated GoMock package.
slidinglog
Package slidinglog is a generated GoMock package.
Package slidinglog is a generated GoMock package.

Jump to

Keyboard shortcuts

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