rate

package
v0.0.0-...-ac4703f Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default() gin.HandlerFunc

Default create a new Limiter with default Limit params.

func Limit

func Limit(c int, r rate.Limit, b int) gin.HandlerFunc

Limit creates a new Limiter with max capacity c, Limit r and Burst size b. Then returns a gin middleware.

Types

type Limiter

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

Limiter combines the IRU algorithm to rate limit. A Limiter is a cache where all keyed limiter stored.

func New

func New(capacity int, r rate.Limit, b int) *Limiter

New new a Limiter that allows each keyed limiter up to rate r and permits bursts of at most b tokens.

func (*Limiter) Allow

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

Allow reports whether a event happens now. If the keyed limiter of the event does not exist in the cache, set a new keyed limiter to the cache.

func (*Limiter) Burst

func (l *Limiter) Burst(key string) (b int, ok bool)

Burst returns the maximum burst size of the keyed limiter.

func (*Limiter) Limit

func (l *Limiter) Limit(key string) (r rate.Limit, ok bool)

Limit returns the maximum overall event rate of the keyed limiter.

func (*Limiter) ServeHTTP

func (l *Limiter) ServeHTTP(c *gin.Context)

func (*Limiter) Set

func (l *Limiter) Set(key string)

Set sets a new key limiter in the cache.

func (*Limiter) SetBurst

func (l *Limiter) SetBurst(key string, newBurst int)

SetBurst sets a new Burst size for the keyed limiter.

func (*Limiter) SetLimit

func (l *Limiter) SetLimit(key string, newLimit rate.Limit)

SetLimit sets new Limit for the keyed limiter.

Jump to

Keyboard shortcuts

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