rate

package
v1.0.0-mainnet-hotfix-1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistryCfx = NewRegistry()
View Source
var DefaultRegistryEth = NewRegistry()

Functions

This section is empty.

Types

type Config

type Config struct {
	IpLimitOpts map[string]Option   // ip rate limit configs
	WhiteList   map[string]struct{} // white list
}

type IpLimiter

type IpLimiter struct {
	Option
	// contains filtered or unexported fields
}

IpLimiter is used to limit requests from different users.

func NewIpLimiter

func NewIpLimiter(rate rate.Limit, burst int) *IpLimiter

func (*IpLimiter) Allow

func (l *IpLimiter) Allow(ip string, n int) bool

func (*IpLimiter) GC

func (l *IpLimiter) GC(timeout time.Duration)

func (*IpLimiter) Update

func (l *IpLimiter) Update(option Option) bool

type Option

type Option struct {
	Rate  rate.Limit
	Burst int
}

func NewOption

func NewOption(r int, b int) Option

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) AutoReload

func (m *Registry) AutoReload(interval time.Duration, reloader func() *Config)

func (*Registry) GC

func (m *Registry) GC(timeout time.Duration)

func (*Registry) Get

func (m *Registry) Get(name string) (*IpLimiter, bool)

func (*Registry) GetOrRegister

func (m *Registry) GetOrRegister(name string, rate rate.Limit, burst int) *IpLimiter

func (*Registry) WhiteListed

func (m *Registry) WhiteListed(name string) bool

Jump to

Keyboard shortcuts

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