httpmw

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRequests is the default max requests per window.
	DefaultRequests = 100
	// DefaultWindow is the default time window for rate limiting.
	DefaultWindow = time.Minute
)

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(cfg AuthConfig, next http.Handler) http.Handler

AuthMiddleware provides API key authentication for HTTP handlers.

func CORS

func CORS(next http.Handler) http.Handler

CORS adds CORS headers to HTTP responses.

func GracefulShutdown

func GracefulShutdown(srv *http.Server)

GracefulShutdown runs an HTTP server with graceful shutdown on SIGINT/SIGTERM.

func JSONResponse

func JSONResponse(w http.ResponseWriter, status int, data any)

JSONResponse writes a JSON response with the given status code and data.

func RequireContentType

func RequireContentType(contentType string) func(http.Handler) http.Handler

RequireContentType middleware validates Content-Type on write methods

Types

type AuthConfig

type AuthConfig struct {
	APIKey      string
	ExemptPaths []string
}

AuthConfig holds configuration for authentication middleware.

type RateLimiter

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

RateLimiter provides per-IP rate limiting for HTTP handlers.

func NewDefault

func NewDefault() *RateLimiter

NewDefault creates a rate limiter with 100 requests per minute.

func NewRateLimiter

func NewRateLimiter(requests int, window time.Duration) *RateLimiter

NewRateLimiter creates a rate limiter with the given requests per window.

func (*RateLimiter) Middleware

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

Middleware wraps an http.Handler with per-IP rate limiting.

Jump to

Keyboard shortcuts

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