Documentation ¶
Index ¶
- Constants
- func GenerateRandomLimitKey(limitType LimitType) (string, error)
- type Config
- type FixedWindowOption
- type KeyInfo
- type KeyLoader
- type KeysetFilter
- type LimitAlgoType
- type LimitRule
- type LimitType
- type Registry
- func (m *Registry) AutoReload(interval time.Duration, reloader func() (*Config, error))
- func (r *Registry) Create(ctx context.Context, resource, group string) (rate.Limiter, error)
- func (r *Registry) GetGroupAndKey(ctx context.Context, resource string) (group, key string, err error)
- func (r *Registry) SVipStatusFromContext(ctx context.Context) (svip int, ok bool)
- type Strategy
- type TokenBucketOption
Constants ¶
View Source
const ( LimitKeyCacheSize = 5000 LimitKeyExpirationTTL = 90 * time.Second )
View Source
const ( // pre-defined default strategy name DefaultStrategy = "default" // pre-defined strategy config key prefix ConfigStrategyPrefix = "ratelimit.strategy." )
View Source
const (
GCScheduleInterval = 5 * time.Minute
)
View Source
const (
LimitKeyLength = 32
)
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomLimitKey ¶
Types ¶
type FixedWindowOption ¶
FixedWindowOption limit option for fixed window
func (*FixedWindowOption) UnmarshalJSON ¶
func (fwo *FixedWindowOption) UnmarshalJSON(data []byte) error
UnmarshalJSON implements `json.Unmarshaler`
type KeyLoader ¶
type KeyLoader struct {
// contains filtered or unexported fields
}
func NewKeyLoader ¶
func NewKeyLoader(ksload ksLoadFunc) *KeyLoader
type KeysetFilter ¶
type LimitAlgoType ¶
type LimitAlgoType string
const ( // rate limit algorithms, only `fixed_window` and `token bucket` are supported for now. LimitAlgoFixedWindow LimitAlgoType = "fixed_window" LimitAlgoTokenBucket LimitAlgoType = "token_bucket" )
type LimitRule ¶
type LimitRule struct { Algo LimitAlgoType Option interface{} }
LimitRule resource limit rule
func (*LimitRule) UnmarshalJSON ¶
type Registry ¶
func NewRegistry ¶
func (*Registry) AutoReload ¶
func (*Registry) GetGroupAndKey ¶
type Strategy ¶
type Strategy struct { ID uint32 // strategy ID Name string // strategy name LimitOptions map[string]interface{} // resource => limit option MD5 [md5.Size]byte `json:"-"` // config data fingerprint }
Strategy rate limit strategy
func NewStrategy ¶
func (*Strategy) UnmarshalJSON ¶
UnmarshalJSON implements `json.Unmarshaler`
type TokenBucketOption ¶
FixedWindowOption limit option for token bucket
func NewTokenBucketOption ¶
func NewTokenBucketOption(r, b int) TokenBucketOption
Click to show internal directories.
Click to hide internal directories.