limiter

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const KeyPrefix = "hyper:limiter:"

KeyPrefix the prefix of key

Variables

This section is empty.

Functions

This section is empty.

Types

type Limit

type Limit struct {
	Rate   int
	Burst  int
	Period time.Duration
}

Limit struct define Limit

func PerHour

func PerHour(rate int) Limit

PerHour return limit base per hour

func PerMinute

func PerMinute(rate int) Limit

PerMinute return limit base per minute

func PerSecond

func PerSecond(rate int) Limit

PerSecond return limit base per second

func (Limit) String

func (l Limit) String() string

type Limiter

type Limiter interface {
	Acquire(string, Limit) (Result, error)
}

Limiter interface

type Result

type Result struct {
	Limit      Limit
	Acquired   bool
	Remaining  int
	RetryAfter int
	ResetAfer  int
}

Result define the result of acquire lock

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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