betterratelimit

package module
v0.0.0-...-d835e5b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

README

betterratelimit

Documentation

Index

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

func BetterRatelimitGetActiveHistory() map[string]uint

get the history of requests of the current second

func BetterRatelimitGetHistory

func BetterRatelimitGetHistory() map[time.Time]map[string]uint

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

type GlobalRatelimitBanPaths struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

type GlobalRatelimitHistory struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL