ratelimit

package
v2.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limit

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

func Parse

func Parse(value string) (Limit, error)

Parse is borrowed from https://github.com/ulule/limiter Copyright (c) 2015-2018 Ulule You can use the simplified format "<limit>-<period>"(burst is 1 by default) or "<limit>-<period>-<burst>", with the given periods:

* "S": second * "M": minute * "H": hour * "D": day

Examples for "<limit>-<period>" format:

* 5.5 reqs/second: "5.5-S" * 10 reqs/minute: "10-M" * 1000 reqs/hour: "1000-H" * 2000 reqs/day: "2000-D"

Examples:

* 0.0055 reqs/second with burst 20: "0.0055-S-20" https://github.com/go-redis/redis_rate/issues/63 * 10 reqs/minute with burst 200: "10-M-200" * 1000 reqs/hour with burst 500: "1000-H-500" * 2000 reqs/day with burst 1000: "2000-D-1000"

func PerDay

func PerDay(rate float64) Limit

func PerDayBurst

func PerDayBurst(rate float64, burst int) Limit

func PerHour

func PerHour(rate float64) Limit

func PerHourBurst

func PerHourBurst(rate float64, burst int) Limit

func PerMinute

func PerMinute(rate float64) Limit

func PerMinuteBurst

func PerMinuteBurst(rate float64, burst int) Limit

func PerSecond

func PerSecond(rate float64) Limit

func PerSecondBurst

func PerSecondBurst(rate float64, burst int) Limit

type Limiter

type Limiter interface {
	Allow() bool
	AllowE() (bool, error)
	AllowCtx(ctx context.Context) bool
	AllowECtx(ctx context.Context) (bool, error)

	ReserveE() (time.Duration, bool, error)
	ReserveECtx(ctx context.Context) (time.Duration, bool, error)

	Wait(ctx context.Context) error
}

type LimiterOption

type LimiterOption func(Limiter)

Directories

Path Synopsis
Package memrate provides a rate limiter.
Package memrate provides a rate limiter.

Jump to

Keyboard shortcuts

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