tokenbucket

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tokenbucket implements the Token Bucket rate limiting algorithm.

Token Bucket allows bursty traffic up to the bucket capacity while continuously refilling tokens at a constant rate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Strategy

type Strategy struct{}

Strategy implements the algorithm.Algorithm interface for Token Bucket.

func New

func New() *Strategy

New creates a new instance of the Token Bucket algorithm strategy.

func (*Strategy) EvaluateMemory

func (s *Strategy) EvaluateMemory(now time.Time, state *algorithm.State, limit int64, window time.Duration) algorithm.Result

EvaluateMemory evaluates the token bucket rate limit state synchronously in RAM. Note: This method expects state modification to be guarded by a mutex from the caller.

func (*Strategy) Name

func (s *Strategy) Name() string

Name returns the unique identifier of the algorithm strategy.

func (*Strategy) RedisScript

func (s *Strategy) RedisScript() string

RedisScript returns the high-performance atomic Lua script for Redis distribution.

Jump to

Keyboard shortcuts

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