slapdash

package module
v0.0.0-...-42b9eb7 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

Never has rate limiting felt so damn good.

slapdash, as the name implies, approaches rate limiting in a careless, hasty, or haphazard manner. instead of having to track agents precisely it uses bloomfilters to rapidly identify the heaviest usage agents quickly and restricts them.

by taking this approach slashdash in its default settings protect an endpoint from a large number of attackers while using O(1) memory, minimal allocations, sub millisecond response times, and a entirely graceful failure scenario all entirely in application, no extra servers, coordination, or databases needed.

limit := slapdash.NewLimiter(rate.NewLimiter(rate.Every(time.Millisecond), 1))
if err := limit.Allow(context.Background(), []byte("user id")); err != nil {
  log.Println("BLOCKED", err)
  return
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analytics

type Analytics struct {
	Banned uint32
}

type Banned

type Banned interface {
	error
	Banned() time.Duration // returns the duration of the ban.
}

represents a banned event.

func NewBanned

func NewBanned(id []byte, duration time.Duration) Banned

type Blocked

type Blocked interface {
	error
	Blocked()
}

represents a blocked event.

func NewBlocked

func NewBlocked(id []byte) Blocked

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(r *rate.Limiter) *Limiter

func (*Limiter) Allow

func (t *Limiter) Allow(ctx context.Context, id []byte) error

func (*Limiter) Analytics

func (t *Limiter) Analytics() Analytics

func (*Limiter) Debug

func (t *Limiter) Debug()

Jump to

Keyboard shortcuts

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