Documentation
¶
Index ¶
- func BuildHandler(ctx context.Context, cfg Config, handler http.Handler) http.Handler
- func CORSMiddleware(origins []string) func(http.Handler) http.Handler
- func RateLimiter(ctx context.Context, readRPS float64, readBurst int, writeRPS float64, ...) func(http.Handler) http.Handler
- func RequestLogger(trustProxy bool, proxyDepth int) func(http.Handler) http.Handler
- type Config
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildHandler ¶
BuildHandler composes the middleware chain around the given handler. Zero-value rate limit fields default to 120/120 read and 60/60 write.
func CORSMiddleware ¶
CORSMiddleware returns middleware that sets CORS headers for the given origins. If origins is empty, no CORS headers are set (same-origin only).
func RateLimiter ¶
func RateLimiter(ctx context.Context, readRPS float64, readBurst int, writeRPS float64, writeBurst int, trustProxy bool, proxyDepth int) func(http.Handler) http.Handler
RateLimiter returns middleware that limits requests per IP address. rps is requests per second, burst is the maximum burst size. When trustProxy is true, X-Forwarded-For / X-Real-Ip headers are used for client IP. The cleanup goroutine exits when ctx is cancelled.
Types ¶
type Config ¶
type Config struct {
BaseURL *baseurl.BaseURL
TrustProxy bool
ProxyDepth int
CORSOrigins []string
ReadRPS float64
ReadBurst int
WriteRPS float64
WriteBurst int
Version string
AdminToken string
MaxSecretSize int // bytes; 0 = default (512000)
MetricsEnabled bool
// ExtraRoutes registers additional routes on the server mux. nil = no extra routes.
ExtraRoutes func(mux *http.ServeMux)
// Middleware is a chain of additional middleware applied after security headers.
// Each function wraps the handler; they are applied in slice order (last = outermost).
Middleware []func(http.Handler) http.Handler
}