bucket

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 2 Imported by: 0

README

  • token bucket

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPRateLimiter

type IPRateLimiter struct {
	// contains filtered or unexported fields
}

IPRateLimiter .

func NewIPRateLimiter

func NewIPRateLimiter(r rate.Limit, b int) *IPRateLimiter

創建API限速由IP。

r : 產token的頻率

直接輸入2就代表每秒產2個token
代入此rate.Every(time.Second*3),則代表每三秒產一個token

b : bucket 最多存幾個token。

func (*IPRateLimiter) GetLimiter

func (i *IPRateLimiter) GetLimiter(ip string) *rate.Limiter

GetLimiter 返回所提供的IP地址的速率限制器(如果存在的话). 否则调用 AddIP 将 IP 地址添加到映射中

Jump to

Keyboard shortcuts

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