limiter

package
v0.0.0-...-5c0bb04 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActLimit

func ActLimit(ctx echo.Context, id, action string, maxCount, period int) int

ActLimit obtaining the remaining executable times

Types

type IPRateLimiter

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

IPRateLimiter rate limiter for ip Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

func NewIPRateLimiter

func NewIPRateLimiter(r rate.Limit, b int) *IPRateLimiter

NewIPRateLimiter return a *IPRateLimiter Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

func (*IPRateLimiter) AddIP

func (i *IPRateLimiter) AddIP(ip string) *rate.Limiter

AddIP creates a new rate limiter and adds it to the ips map, using the IP address as the key Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

func (*IPRateLimiter) GetLimiter

func (i *IPRateLimiter) GetLimiter(ip string) *rate.Limiter

GetLimiter returns the rate limiter for the provided IP address if it exists. Otherwise calls AddIP to add IP address to the map Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

type UserRateLimiter

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

UserRateLimiter rate limiter for user Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

func NewUserRateLimiter

func NewUserRateLimiter(r rate.Limit, b int) *UserRateLimiter

NewUserRateLimiter return a *UserRateLimiter Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

func (*UserRateLimiter) AddUser

func (i *UserRateLimiter) AddUser(userKey string) *rate.Limiter

AddUser creates a new rate limiter and adds it to the users map, using the User address as the key Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

func (*UserRateLimiter) GetLimiter

func (i *UserRateLimiter) GetLimiter(userKey string) *rate.Limiter

GetLimiter returns the rate limiter for the provided user key if it exists. Otherwise calls AddUser to add user key to the map Ref: https://dev.to/plutov/rate-limiting-http-requests-in-go-based-on-ip-address-542g

Jump to

Keyboard shortcuts

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