ip

package
v2.0.61 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option is IpRateLimit option.

func WithBucket added in v2.0.35

func WithBucket(size int) Option

WithBucket max bucket num.

func WithExcludes

func WithExcludes(ips []string) Option

WithExcludes bursts of at most b tokens.

func WithMaxQuota

func WithMaxQuota(max int) Option

WithMaxQuota bursts of at most b tokens.

func WithSecondLimit

func WithSecondLimit(perSecond rate.Limit) Option

WithSecondLimit with Limit is represented as number of events per second.

type RateLimiter

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

RateLimiter ip rate limiter

func NewRateLimiter

func NewRateLimiter(opts ...Option) *RateLimiter

func (*RateLimiter) Get added in v2.0.35

func (i *RateLimiter) Get(ip string) *rate.Limiter

Get returns the rate limiter for the provided IP address if it exists. Otherwise, calls AddIP to add IP address to the map

func (*RateLimiter) GetExcludes

func (i *RateLimiter) GetExcludes() []string

func (*RateLimiter) Set added in v2.0.35

func (i *RateLimiter) Set(ip string) *rate.Limiter

Set creates a new rate limiter and adds it to the ips map, using the IP address as the key

Jump to

Keyboard shortcuts

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