limiter

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TokenBucket

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

TokenBucket is a token bucket rate limiter used to limit the frequency of requests. Its working principle is: over a period of time, it generates a certain number of tokens. For each request, if the number of tokens is ≥1, the request is allowed; otherwise, it is rejected. This ensures that the request frequency does not exceed the specified rate over a period of time.

func NewTokenBucket

func NewTokenBucket(rate float64, capacity int) *TokenBucket

func (*TokenBucket) Allow

func (tb *TokenBucket) Allow() bool

Jump to

Keyboard shortcuts

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