Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateRandomLimitKey(limitType int) (string, error)
- func JsonUnmarshalStrategyRules(data []byte) (map[string]Option, error)
- type Config
- type IpLimiter
- type IpLimiterSet
- type KeyBasedIpLimiterSet
- type KeyInfo
- type KeyLimiter
- type KeyLimiterSet
- type KeysetFilter
- type KeysetLoader
- type Limiter
- type LimiterSet
- type Option
- type Registry
- type Strategy
- type VisitContext
Constants ¶
View Source
const ( DefaultStrategy = "default" LimitKeyCacheSize = 5000 LimitKeyExpirationTTL = 75 * time.Second )
View Source
const ( // limit types LimitTypeByKey = iota LimitTypeByIp ConfigStrategyPrefix = "ratelimit.strategy." )
View Source
const (
LimitKeyLength = 16
)
Variables ¶
View Source
var ( DefaultRegistryCfx = NewRegistry() DefaultRegistryEth = NewRegistry() )
Functions ¶
func GenerateRandomLimitKey ¶
Types ¶
type IpLimiter ¶
type IpLimiter struct {
// contains filtered or unexported fields
}
IpLimiter limiting by IP address
func NewIpLimiter ¶
type IpLimiterSet ¶
type IpLimiterSet struct {
// contains filtered or unexported fields
}
IpLimiterSet limiting by IP address
func NewIpLimiterSet ¶
func NewIpLimiterSet(s *Strategy) *IpLimiterSet
func (IpLimiterSet) Get ¶
func (ls IpLimiterSet) Get(vc *VisitContext) (Limiter, bool)
Get returns limiter for current visit context
type KeyBasedIpLimiterSet ¶
type KeyBasedIpLimiterSet struct {
// contains filtered or unexported fields
}
KeyBasedIpLimiterSet limiting by IP address yet grouped by limit key
func NewKeyBasedIpLimiterSet ¶
func NewKeyBasedIpLimiterSet(s *Strategy) *KeyBasedIpLimiterSet
func (KeyBasedIpLimiterSet) Get ¶
func (ls KeyBasedIpLimiterSet) Get(vc *VisitContext) (Limiter, bool)
Get returns limiter for current visit context
type KeyLimiter ¶
type KeyLimiter struct {
// contains filtered or unexported fields
}
KeyLimiter limiting by limit key
func NewKeyLimiter ¶
func NewKeyLimiter(option Option) *KeyLimiter
func (*KeyLimiter) Allow ¶
func (l *KeyLimiter) Allow(vc *VisitContext, n int) bool
type KeyLimiterSet ¶
type KeyLimiterSet struct {
// contains filtered or unexported fields
}
KeyLimiterSet limiting by key
func NewKeyLimiterSet ¶
func NewKeyLimiterSet(s *Strategy) *KeyLimiterSet
func (KeyLimiterSet) Get ¶
func (ls KeyLimiterSet) Get(vc *VisitContext) (Limiter, bool)
Get returns limiter for current visit context
type KeysetFilter ¶
type KeysetLoader ¶
type KeysetLoader func(filter *KeysetFilter) ([]*KeyInfo, error)
KeysetLoader limit keyset loader
type LimiterSet ¶
type LimiterSet interface { Get(vc *VisitContext) (Limiter, bool) GC(timeout time.Duration) Update(s *Strategy) }
LimiterSet limiter set assembled by strategy
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) AutoReload ¶
type Strategy ¶
type Strategy struct { ID uint32 // strategy ID Name string // strategy name Rules map[string]Option // limit rules: rule name => rule option MD5 [md5.Size]byte `json:"-"` // config data fingerprint }
Strategy rate limit strategy
type VisitContext ¶
Click to show internal directories.
Click to hide internal directories.