ratelimiting

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimiting provides a per-key rate limiter interface using the token bucket algorithm.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter interface {
	Allow(ctx context.Context, key string) (bool, error)
	Close() error
}

RateLimiter limits the rate of operations per key.

func NewInMemoryRateLimiter

func NewInMemoryRateLimiter(requestsPerSec float64, burstSize int) RateLimiter

NewInMemoryRateLimiter returns a RateLimiter that uses per-key limiters in memory.

Example
package main

import (
	"context"
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v4/ratelimiting"
)

func main() {
	limiter := ratelimiting.NewInMemoryRateLimiter(10.0, 5)

	allowed, err := limiter.Allow(context.Background(), "user-123")
	if err != nil {
		panic(err)
	}

	fmt.Println(allowed)
}
Output:
true

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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