middleware

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(validKeys []string) func(http.Handler) http.Handler

Auth returns a middleware that validates API keys using constant-time comparison.

func Logger

func Logger(logger *slog.Logger) func(http.Handler) http.Handler

Logger returns a structured logging middleware.

Types

type RateLimiter

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

RateLimiter provides per-key rate limiting.

func NewRateLimiter

func NewRateLimiter(rps float64, burst int) *RateLimiter

NewRateLimiter creates a new rate limiter with a cleanup goroutine.

func (*RateLimiter) Close

func (rl *RateLimiter) Close()

Close stops the cleanup goroutine. Safe to call multiple times.

func (*RateLimiter) Middleware

func (rl *RateLimiter) Middleware() func(http.Handler) http.Handler

Middleware returns a rate limiting middleware. Always rate limits by IP address to prevent key manipulation attacks.

Jump to

Keyboard shortcuts

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