ratelimits

package module
v0.0.0-...-3611cbf Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 3 Imported by: 0

README

rate-limits

Rate limiting using various strategies and storage backends such as redis & memcached

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.0.1"

Functions

func GranularityFromString

func GranularityFromString(granularityStr string)

func NewMemoryStorage

func NewMemoryStorage(options ...string) *memoryStorage

func Parse

func Parse(limitStr string)

func ParseMany

func ParseMany(limitStr string)

Types

type Counter

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

func NewCounter

func NewCounter() *Counter

func (*Counter) AddItems

func (c *Counter) AddItems(items ...interface{})

func (*Counter) Get

func (c *Counter) Get(item interface{}) int

func (*Counter) MostCommon

func (c *Counter) MostCommon(n int) (items []CounterItem)

TODO: is it possible to get the most common without popping and pushing? O(n log k)

type CounterItem

type CounterItem struct {
	Value interface{}
	Count int
}

type MovingWindowSupport

type MovingWindowSupport interface {
	AcquireEntry(key string, limit int, expiry int, amount int) bool
	GetMovingWindow(key string, limit int, expiry int) (int, int)
}

type StorageBase

type StorageBase interface {
	Incr() int
	Get(key string) int       // use key to get the counter value
	GetExpiry(key string) int // use key to get the expiry
	Check() bool              //  check if storage is healthy
	Reset() int               //  reset storage to clear limits
	Clear(key string)         // resets the rate limit key
}

Directories

Path Synopsis
storages

Jump to

Keyboard shortcuts

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