ratelimit

package
v1.2.0-Beta.2.0...-bcfade6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRatelimit = &Ratelimit{
		Current:         0,
		AfterClearCount: 0,
		TempBan:         false,
		TempBannedAt:    0,
		PermBannedAt:    0,
		TotalBans:       0,
	}
	TempBanReset = 7 * 24 * time.Hour
)

Functions

This section is empty.

Types

type Ratelimit

type Ratelimit struct {
	Current         int   `json:"current"`
	AfterClearCount int   `json:"after_clear_count"`
	TempBan         bool  `json:"temp_ban"`
	TempBannedAt    int64 `json:"temp_banned_at"`
	PermBannedAt    int64 `json:"perm_banned_at"`
	TotalBans       int   `json:"total_bans"`
}

func (*Ratelimit) PatchPerm

func (r *Ratelimit) PatchPerm()

func (*Ratelimit) PatchTemp

func (r *Ratelimit) PatchTemp()

func (*Ratelimit) Unpatch

func (r *Ratelimit) Unpatch()

type Ratelimiter

type Ratelimiter struct {
	Limit         int
	Reset         int
	NextReset     time.Time
	RPrefix       string
	TempBanLength time.Duration
	TempBanAfter  int
	PermBanAfter  int
}

func NewRatelimiter

func NewRatelimiter(opts RatelimiterOptions) *Ratelimiter

func (*Ratelimiter) HasExpired

func (r *Ratelimiter) HasExpired(ratelimit *Ratelimit) bool

func (*Ratelimiter) Ratelimit

func (r *Ratelimiter) Ratelimit(next http.Handler) http.Handler

type RatelimiterOptions

type RatelimiterOptions struct {
	Limit         int
	Reset         int
	RedisPrefix   string
	TempBanLength time.Duration
	TempBanAfter  int
	PermBanAfter  int
}

Jump to

Keyboard shortcuts

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