Documentation
¶
Index ¶
- Constants
- func AuthMiddleware(cfg AuthConfig, next http.Handler) http.Handler
- func CORS(next http.Handler) http.Handler
- func GracefulShutdown(srv *http.Server)
- func JSONResponse(w http.ResponseWriter, status int, data any)
- func RequireContentType(contentType string) func(http.Handler) http.Handler
- type AuthConfig
- type RateLimiter
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 GracefulShutdown ¶
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.
Types ¶
type AuthConfig ¶
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.
Click to show internal directories.
Click to hide internal directories.