Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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