- Zero external dependencies - Only uses Go standard library
- Sensible defaults - Works out of the box
- Options pattern - Fully configurable when needed
- Concurrent safe - Safe for use across goroutines
Installation
Middlewares are included with Mizu. Import the specific middleware you need:Quick Start
A typical production setup:Categories
Authentication
Secure your endpoints with various authentication methods:Security
Protect your application from common web vulnerabilities:| Middleware | Description |
|---|---|
| helmet | Security headers (CSP, HSTS, etc.) |
| secure | HTTPS enforcement and security features |
| ipfilter | IP whitelist/blacklist |
| honeypot | Detect and block malicious requests |
| captcha | CAPTCHA verification (reCAPTCHA, hCaptcha, Turnstile) |
| cors | Cross-Origin Resource Sharing |
| cors2 | Enhanced CORS with preflight caching |
| rbac | Role-based access control |
| signature | Request signature verification |
Rate Limiting & Resilience
Control request rates and protect against overload:| Middleware | Description |
|---|---|
| ratelimit | Token bucket rate limiting |
| circuitbreaker | Circuit breaker pattern |
| bulkhead | Bulkhead isolation pattern |
| throttle | Request throttling |
| concurrency | Concurrency limiting |
| adaptive | Adaptive rate limiting |
Request Processing
Validate and transform incoming requests:| Middleware | Description |
|---|---|
| bodylimit | Limit request body size |
| contenttype | Validate Content-Type |
| validator | Request validation rules |
| header | Header manipulation |
| methodoverride | HTTP method override |
| bodyclose | Auto-close request body |
| bodydump | Dump request/response bodies |
| requestsize | Request size tracking |
| sanitizer | Input sanitization |
| transformer | Request/response transformation |
| filter | Request filtering |
Response Processing
Transform and enhance outgoing responses:| Middleware | Description |
|---|---|
| compress | Gzip/deflate compression |
| envelope | Response envelope wrapper |
| responsesize | Response size tracking |
| vary | Vary header management |
| errorpage | Custom error pages |
| hypermedia | Hypermedia response helpers |
Caching
Control HTTP caching behavior:| Middleware | Description |
|---|---|
| cache | Set Cache-Control headers |
| nocache | Prevent caching |
| etag | ETag generation |
| lastmodified | Last-Modified headers |
URL Handling
Redirect and rewrite URLs:Networking & Proxy
Handle proxy headers and reverse proxying:Request Context
Enhance request handling:Real-time
Support real-time communication:Static Files
Serve static content:Operations & Monitoring
Tools for production operations:| Middleware | Description |
|---|---|
| version | API versioning |
| maintenance | Maintenance mode |
| pprof | Profiling endpoints |
| healthcheck | Health check endpoints |
| metrics | Custom metrics collection |
| prometheus | Prometheus metrics endpoint |
| expvar | Expvar metrics endpoint |
| logger | Request logging |
| requestlog | Detailed request logging |
| responselog | Response logging |
Advanced
Specialized functionality:| Middleware | Description |
|---|---|
| feature | Feature flags |
| multitenancy | Multi-tenant support |
| chaos | Chaos engineering |
| mirror | Request mirroring |
| fingerprint | Request fingerprinting |
| canary | Canary deployment routing |
| audit | Audit logging |
| idempotency | Idempotency key handling |
| retry | Automatic request retries |
| hedge | Hedged requests |
| fallback | Fallback handlers |
| mock | Request mocking |
Connection & Protocol
Connection and protocol handling:Internationalization
Locale and timezone handling:External Integrations
Third-party service integrations:Bot & Client Detection
Client identification and validation:| Middleware | Description |
|---|---|
| bot | Bot detection |
| xrequestedwith | X-Requested-With validation |
Usage Patterns
Global middleware
Apply to all routes:Route-specific middleware
Apply to specific routes:Group middleware
Apply to a group of routes:Conditional middleware
Skip middleware based on conditions:Best Practices
- Order matters - Place
recoverfirst to catch all panics - Use timeouts - Always set request timeouts in production
- Rate limit - Protect public endpoints from abuse
- Security headers - Use
helmetfor recommended security headers - Request IDs - Add
requestidfor tracing and debugging
Next Steps
- Learn about writing custom middleware
- Explore individual middleware documentation in the sidebar