ratelimit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: GPL-3.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ratelimit 提供按 key 的滑动窗口限流,用于桥接的配对尝试节流。 具体限制由 protocol.json 定义并在构造调用处注入。

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 是按 key 的滑动窗口计数器:每个 key 在 window 内最多放行 limit 次。

func NewLimiter

func NewLimiter(limit int, window time.Duration) *Limiter

NewLimiter 构造窗口 window 内上限 limit 次的限流器。

func (*Limiter) Allow

func (l *Limiter) Allow(key string) bool

Allow 记录一次 key 的尝试:窗口内未超上限则记账放行,否则拒绝且不记账。

Jump to

Keyboard shortcuts

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