ratelimit

package
v0.68.0-prev2 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT 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 `long:"requests" description:" "`

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

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