Documentation ¶
Overview ¶
package rkmidlimit provide options
Index ¶
- Constants
- type BeforeCtx
- type BootConfig
- type Limiter
- type NoopLimiter
- type Option
- func ToOptions(config *BootConfig, entryName, entryType string) []Option
- func WithAlgorithm(algo string) Option
- func WithEntryNameAndType(entryName, entryType string) Option
- func WithGlobalLimiter(l Limiter) Option
- func WithLimiterByPath(path string, l Limiter) Option
- func WithMockOptionSet(mock OptionSetInterface) Option
- func WithReqPerSec(reqPerSec int) Option
- func WithReqPerSecByPath(path string, reqPerSec int) Option
- type OptionSetInterface
- type ZeroRateLimiter
Constants ¶
const ( TokenBucket = "tokenBucket" LeakyBucket = "leakyBucket" DefaultLimit = 1000000 GlobalLimiter = "rk-limiter" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BeforeCtx ¶
type BeforeCtx struct { Input struct { UrlPath string } Output struct { ErrResp *rkerror.ErrorResp } }
BeforeCtx context for Before() function
func NewBeforeCtx ¶
func NewBeforeCtx() *BeforeCtx
NewBeforeCtx create new BeforeCtx with fields initialized
type BootConfig ¶
type BootConfig struct { Enabled bool `yaml:"enabled" json:"enabled"` Algorithm string `yaml:"algorithm" json:"algorithm"` ReqPerSec int `yaml:"reqPerSec" json:"reqPerSec"` Paths []struct { Path string `yaml:"path" json:"path"` ReqPerSec int `yaml:"reqPerSec" json:"reqPerSec"` } `yaml:"paths" json:"paths"` }
BootConfig for YAML
type Option ¶
type Option func(*optionSet)
Option if for middleware options while creating middleware
func ToOptions ¶
func ToOptions(config *BootConfig, entryName, entryType string) []Option
ToOptions convert BootConfig into Option list
func WithAlgorithm ¶
WithAlgorithm provide algorithm of rate limit. - tokenBucket - leakyBucket
func WithEntryNameAndType ¶
WithEntryNameAndType provide entry name and entry type.
func WithGlobalLimiter ¶
WithGlobalLimiter provide user defined Limiter.
func WithLimiterByPath ¶
WithLimiterByPath provide user defined Limiter by method.
func WithMockOptionSet ¶
func WithMockOptionSet(mock OptionSetInterface) Option
WithMockOptionSet provide mock OptionSetInterface
func WithReqPerSec ¶
WithReqPerSec Provide request per second.
func WithReqPerSecByPath ¶
WithReqPerSecByPath Provide request per second by method.
type OptionSetInterface ¶
type OptionSetInterface interface { GetEntryName() string GetEntryType() string Before(*BeforeCtx) BeforeCtx(*http.Request) *BeforeCtx }
OptionSetInterface mainly for testing purpose
func NewOptionSet ¶
func NewOptionSet(opts ...Option) OptionSetInterface
NewOptionSet Create new optionSet with options.
func NewOptionSetMock ¶
func NewOptionSetMock(before *BeforeCtx) OptionSetInterface
NewOptionSetMock for testing purpose
type ZeroRateLimiter ¶
type ZeroRateLimiter struct{}
ZeroRateLimiter will block requests.
func (*ZeroRateLimiter) Limit ¶
func (l *ZeroRateLimiter) Limit() error
Limit will block request and return error