middleware

package
v0.0.0-...-9656c79 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPManager

func IPManager(name string) func(r *ghttp.Request)

func PathManager

func PathManager(name string) func(r *ghttp.Request)

func RateLimitMiddleware

func RateLimitMiddleware(name string) func(r *ghttp.Request)

func SecureRequestMiddleware

func SecureRequestMiddleware(name string) func(*ghttp.Request)

func TrafficLogger

func TrafficLogger(name string) func(*ghttp.Request)

Types

type FixedWindow

type FixedWindow struct {
	WindowStart time.Time // 窗口开始时间

	MaxRequests int           // 窗口最大请求数
	WindowSize  time.Duration // 窗口大小
	Counter     int           // 计数器
	MaxCounter  int           // 最大计数器
	BanCounter  int           // 封禁计数器
	BanDuration int           // 常规封禁时间,单位秒
	// contains filtered or unexported fields
}

FixedWindow 固定窗口结构体

func (*FixedWindow) Allow

func (rl *FixedWindow) Allow(ctx context.Context, ip string) bool

type LeakyBucket

type LeakyBucket struct {
	Capacity     int           // 桶容量
	Remaining    int           // 当前桶里的水
	LeakInterval time.Duration // 漏水速率
	LastLeakTime time.Time     // 上次漏水时间
	Counter      int           // 计数器
	MaxCounter   int           // 最大计数器
	BanCounter   int           // 封禁计数器
	BanDuration  int           // 常规封禁时间,单位秒
	// contains filtered or unexported fields
}

LeakyBucket 漏桶结构体

func (*LeakyBucket) Allow

func (rl *LeakyBucket) Allow(ctx context.Context, ip string) bool

type RLInterface

type RLInterface interface {
	Allow(ctx context.Context, ip string) bool
}

func NewRateLimiter

func NewRateLimiter(ctx context.Context) RLInterface

type SlidingWindow

type SlidingWindow struct {
	Window      time.Duration // 窗口大小
	MaxReq      int           // 最大队列数
	Counter     int           // 计数器
	MaxCounter  int           // 最大计数器
	BanCounter  int           // 封禁计数器
	BanDuration int           // 常规封禁时间,单位秒
	// contains filtered or unexported fields
}

SlidingWindow 滑动窗口结构体

func (*SlidingWindow) Allow

func (rl *SlidingWindow) Allow(ctx context.Context, ip string) bool

type TokenBucket

type TokenBucket struct {
	Tokens          int       // 当前令牌数
	MaxTokens       int       // 最大令牌数
	TokensPerSecond int       // 令牌生成速率
	LastTime        time.Time // 上个令牌生成时间
	Counter         int       // 计数器
	MaxCounter      int       // 最大计数器
	BanCounter      int       // 封禁计数器
	BanDuration     int       // 常规封禁时间,单位秒
	// contains filtered or unexported fields
}

TokenBucket 令牌桶结构体

func (*TokenBucket) Allow

func (rl *TokenBucket) Allow(ctx context.Context, ip string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳