ratelimit

package
v6.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package ratelimit API 限流中间件

这是以用户或是客户端为单位的限流中间件,并不能按 API 进行细化的限流。

提供了对以下报头的支持: - X-Rate-Limit-Limit: 同一个时间段所允许的请求的最大数目; - X-Rate-Limit-Remaining: 在当前时间段内剩余的请求的数量; - X-Rate-Limit-Reset: 为了得到最大请求数所需等待的 UNIX 时间。

所有数据保存在 web.Cache 之中,缓存服务重启后数据也将重置。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenIP

func GenIP(ctx *web.Context) (string, error)

GenIP 用于生成区分令牌桶的 IP 地址

func New

func New(c web.Cache, capacity uint64, rate time.Duration, fn GenFunc) web.Middleware

New 声明 [Ratelimit] 对象

rate 拿令牌的频率; fn 为令牌桶名称的产生方法,默认为用户的 IP;

Types

type GenFunc

type GenFunc = func(*web.Context) (string, error)

GenFunc 用于生成用户唯一 ID 的函数

用于区分令牌桶所属的用户

Jump to

Keyboard shortcuts

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