Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BanControl ¶
type BanControl struct {
// Label of this control.
Label string
}
BanControl bans all the request.
func NewBanControl ¶
func NewBanControl(label string) *BanControl
NewBanControl return a new BanControl with the given label.
func (*BanControl) Acquire ¶
func (c *BanControl) Acquire() bool
Acquire permission from BanControl. Permission is never granted.
type LimitController ¶
type LimitController interface {
// Start the rate limit controller.
Start()
// Acquire permission to perform certain things.
// The permission is granted according to the rate limit rule.
Acquire() bool
}
LimitController defines behaviors of a rate limit control.
type NoopControl ¶
type NoopControl struct {
// Label of this control.
Label string
}
NoopControl does not perform any rate limit.
func NewNoopControl ¶
func NewNoopControl(label string) *NoopControl
NewNoopControl return a new NoopControl with the given label.
func (*NoopControl) Acquire ¶
func (c *NoopControl) Acquire() bool
Acquire permission from NoopControl. Permission is granted immediately since it does not perform any rate limit.
type RPMControl ¶
type RPMControl struct {
// Label of this control.
Label string
// Rate holds the number of requests per minute.
Rate int
// contains filtered or unexported fields
}
RPMControl provides requests per minute rate limit control.
func NewRPMControl ¶
func NewRPMControl(label string, rate int) *RPMControl
NewRPMControl return a new RPMControl with the given label and rate.
func (*RPMControl) Acquire ¶
func (c *RPMControl) Acquire() bool
Acquire permission from RPMControl. Permission is granted at a rate of N requests per minute.
func (*RPMControl) Start ¶
func (c *RPMControl) Start()
Start running RPMControl. A goroutine is launched to govern the rate limit of Acquire().
type RPSControl ¶
type RPSControl struct {
// Label of this control.
Label string
// Rate holds the number of requests per second.
Rate int
// contains filtered or unexported fields
}
RPSControl provides requests per second rate limit control.
func NewRPSControl ¶
func NewRPSControl(label string, rate int) *RPSControl
NewRPSControl return a new RPSControl with the given label and rate.
func (*RPSControl) Acquire ¶
func (c *RPSControl) Acquire() bool
Acquire permission from RPSControl. Permission is granted at a rate of N requests per second.
func (*RPSControl) Start ¶
func (c *RPSControl) Start()
Start running RPSControl. A goroutine is launched to govern the rate limit of Acquire().
type Zone ¶
type Zone struct {
// Host specifies the URL host of the location(s).
// It supports using wildcard '*' for matching part of the host name.
// E.g. "*.github.com" matches both "www.github.com" and "api.github.com".
Host string
// Path specifies the URL path of the location(s).
// It supports using wildcard '*' for matching part of the path.
// E.g. "/*" matches both "/atom" and "/github".
Path string
// LimitBy specifies the rate limit subject of the location(s).
// Rate limit can be performed by "host" or "path".
LimitBy string
Shared bool
// Control specifies which rate limit controller is used.
Control string
// Rate specifies the rate of the rate limit controller.
Rate int
// contains filtered or unexported fields
}
A Zone holds the settings and states of the rate limited location(s).
func (*Zone) GetController ¶
func (z *Zone) GetController(host string, path string) LimitController
GetController returns the rate limit controller of a location.