rate

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rate supply functionality about QPS for example rate limiting

Index

Constants

View Source
const (
	DefaultRate = 2147483647
)

constant qps default rate

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiters

type Limiters struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Limiters manages all rate limiters. it is thread safe and singleton. it create new limiters and try to limit request. each limiter has a unique name.

func GetRateLimiters

func GetRateLimiters() *Limiters

GetRateLimiters get qps rate limiters

func (*Limiters) DeleteRateLimiter

func (qpsL *Limiters) DeleteRateLimiter(name string)

DeleteRateLimiter delete rate limiter

func (*Limiters) TryAccept

func (qpsL *Limiters) TryAccept(name string, qps, burst int) bool

TryAccept try to accept a request. if limiter can not accept a request, it returns false name is the limiter name qps is not necessary if the limiter already exists

func (*Limiters) UpdateRateLimit

func (qpsL *Limiters) UpdateRateLimit(name string, qps, burst int)

UpdateRateLimit will update the old limiters

Jump to

Keyboard shortcuts

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