ratelimit

package
v1.9.22 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 8 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 is the structure for request rate limiter

func NewCookieKeyModeLimiter

func NewCookieKeyModeLimiter(rate float64, capacity int64, cookieKey string) *Limiter

NewCookieKeyModeLimiter todo

func NewGlobalModeLimiter

func NewGlobalModeLimiter(rate float64, capacity int64) *Limiter

NewGlobalModeLimiter todo

func NewHeaderKeyModeLimiter

func NewHeaderKeyModeLimiter(rate float64, capacity int64, headerKey string) *Limiter

NewHeaderKeyModeLimiter todo

func NewRemoteIPModeLimiter

func NewRemoteIPModeLimiter(rate float64, capacity int64) *Limiter

NewRemoteIPModeLimiter todo

func (*Limiter) GetLimiter

func (l *Limiter) GetLimiter(r *http.Request) flowcontrol.RateLimiter

GetLimiter 获取对应的限制器

func (*Limiter) Handler

func (l *Limiter) Handler(next http.Handler) http.Handler

Handler 实现中间件

func (*Limiter) SetMaxSize

func (l *Limiter) SetMaxSize(max int64)

SetMaxSize 设置最大值

func (*Limiter) SetRemoteIPHeader

func (l *Limiter) SetRemoteIPHeader(headers []string)

SetRemoteIPHeader 设置RemoteIP的头

type Mode

type Mode uint

Mode 限制模式

const (
	// GlobalMode 限制所有的请求
	GlobalMode Mode = iota
	// RemoteIPMode 限制远程IP的速率
	RemoteIPMode
	// HeaderKeyMode 根据Header中的特定Key进行限制
	HeaderKeyMode
	// CookieKeyMode 更加cookie中特定的Key进行限制
	CookieKeyMode
)

Jump to

Keyboard shortcuts

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