ratelimit

package
v0.75.8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// How many requests
	Requests int `description:" " long:"requests"`

	// In the last `PerNBlocks` blocks
	PerNBlocks int `description:" " long:"per-n-blocks"`
}

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig allows 500 requests in the last 10 blocks.

type Key

type Key []byte

func (Key) String

func (k Key) String() string

type Rates

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

func New

func New(requests, perNBlocks int) *Rates

func (*Rates) Allow

func (r *Rates) Allow(key string) bool

func (*Rates) Count

func (r *Rates) Count(key string) int

Count returns the number of requests recorded for a given key It returns -1 if the key has been not recorded or evicted.

func (*Rates) NextBlock

func (r *Rates) NextBlock()

Jump to

Keyboard shortcuts

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