keyrate

package module
v0.0.0-...-7ee655a Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 3 Imported by: 0

README

keyrate

Package keyrate wraps limiter from golang.org/x/time/rate to perform key based limiting

See GoDoc for documentation.

Documentation

Overview

Package keyrate wraps Limiter from golang.org/x/time/rate to perform key based limiting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntLimiter

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

An IntLimiter controls how often events are allowed to happen per int key.

func NewIntLimiter

func NewIntLimiter(n rate.Limit, b int) *IntLimiter

NewIntLimiter returns a new IntLimiter with up to rate r and burts of at most b.

func (*IntLimiter) Allow

func (l *IntLimiter) Allow(key int) bool

Allow reports whether one event may happen at time now for the provided key.

func (*IntLimiter) AllowN

func (l *IntLimiter) AllowN(key int, n int) bool

AllowN reports whether n events may happen at time now for the provided key.

type StringLimiter

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

A StringLimiter controls how often events are allowed to happen per string key.

func NewStringLimiter

func NewStringLimiter(n rate.Limit, b int) *StringLimiter

NewStringLimiter returns a new StringLimiter with up to rate r and burts of at most b.

func (*StringLimiter) Allow

func (l *StringLimiter) Allow(key string) bool

Allow reports whether one event may happen at time now for the provided key.

func (*StringLimiter) AllowN

func (l *StringLimiter) AllowN(key string, n int) bool

AllowN reports whether n events may happen at time now for the provided key.

Jump to

Keyboard shortcuts

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