Documentation
¶
Index ¶
- Variables
- func BetterRatelimitGetActiveHistory() map[string]uint
- func BetterRatelimitGetHistory() map[time.Time]map[string]uint
- func BetterRatelimitGlobal(config BetterRatelimitGlobalConfig) echo.MiddlewareFunc
- type BetterRatelimitGlobalConfig
- type GlobalRatelimitBanPaths
- type GlobalRatelimitHistory
- func (c *GlobalRatelimitHistory) Append(path string)
- func (c *GlobalRatelimitHistory) AppendWithWeight(path string, weight uint)
- func (c *GlobalRatelimitHistory) Get(timeHash time.Time) *GlobalRatelimitHistoryTracker
- func (c *GlobalRatelimitHistory) ShouldBlockPath(path string, lastNSeconds uint, maxIncrease uint, miniumRequests uint, ...) bool
- type GlobalRatelimitHistoryTracker
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultBetterRatelimitGlobalConfig = BetterRatelimitGlobalConfig{ Skipper: func(c echo.Context) bool { return false }, DefaultRatelimit: 60, BlockPathAfterNPercentIncrease: 200, CheckBlockPathAccrosLastNSeconds: 10, BlockPathEnableCheckAfterNRequests: 100, BanPathForNTime: time.Duration(time.Second * 60), }
this is the default global ratelimit config
Functions ¶
func BetterRatelimitGetActiveHistory ¶
get the history of requests of the current second
func BetterRatelimitGetHistory ¶
get the full history of requests
func BetterRatelimitGlobal ¶
func BetterRatelimitGlobal(config BetterRatelimitGlobalConfig) echo.MiddlewareFunc
this middleware should be hooked at the root of the router and only be used once
Types ¶
type BetterRatelimitGlobalConfig ¶
type BetterRatelimitGlobalConfig struct {
Skipper func(c echo.Context) bool
DefaultRatelimit uint
BlockPathAfterNPercentIncrease uint // this value should be higher than 101
CheckBlockPathAccrosLastNSeconds uint // this value will check for the increase (BlockPathAfterNPercentIncrease) insidded the last N seconds
BlockPathEnableCheckAfterNRequests uint // this value will enable the increase check if the minimum n requests is met
BanPathForNTime time.Duration
}
type GlobalRatelimitBanPaths ¶
func (*GlobalRatelimitBanPaths) Add ¶
func (c *GlobalRatelimitBanPaths) Add(path string, duration time.Duration)
add path to banned list for n time
func (*GlobalRatelimitBanPaths) IsBanned ¶
func (c *GlobalRatelimitBanPaths) IsBanned(path string) bool
check if path is banned
type GlobalRatelimitHistory ¶
func (*GlobalRatelimitHistory) Append ¶
func (c *GlobalRatelimitHistory) Append(path string)
this function adds the the path to the history of requests
func (*GlobalRatelimitHistory) AppendWithWeight ¶
func (c *GlobalRatelimitHistory) AppendWithWeight(path string, weight uint)
this function adds the the path with a weight to the history of requests
func (*GlobalRatelimitHistory) Get ¶
func (c *GlobalRatelimitHistory) Get(timeHash time.Time) *GlobalRatelimitHistoryTracker
this function returns the ratelimit map of the current minute if non exists yet it creates one
func (*GlobalRatelimitHistory) ShouldBlockPath ¶
func (c *GlobalRatelimitHistory) ShouldBlockPath(path string, lastNSeconds uint, maxIncrease uint, miniumRequests uint, banForNTime time.Duration) bool
this function adds the the path to the history of requests
type GlobalRatelimitHistoryTracker ¶
type GlobalRatelimitHistoryTracker struct {
sync.RWMutex
// contains filtered or unexported fields
}
func (*GlobalRatelimitHistoryTracker) Append ¶
func (c *GlobalRatelimitHistoryTracker) Append(path string, weight uint)
Click to show internal directories.
Click to hide internal directories.