A blazing-fast, production-ready HTTP server built with Go and fasthttp.
| Feature | Description |
|---|---|
| 🚀 High Performance | Built on fasthttp — up to 10x faster than net/http |
| 🔒 Secure by Default | Anti-panic recovery, security headers, rate limiting out of the box |
| 📊 Observable | Built-in Prometheus metrics (/metrics) and health probe (/healthz) |
| ♻️ Graceful Shutdown | Handles SIGINT/SIGTERM, waits for in-flight requests with timeout |
| 🧩 Modular Middleware | Composable chain — add logging, CORS, auth in one line |
| 🐳 Cloud Native | Tiny scratch-based Docker image, zero external dependencies at runtime |
| ⚙️ Zero Config | Works out of the box with sensible defaults, fully tunable via env vars |
- Go 1.22+ (tested with 1.23)
git clone https://github.com/888zxc/microfast.git
cd microfast
make runThat's it. The server is now running on http://localhost:8080.
curl http://localhost:8080/ # Welcome page
curl http://localhost:8080/healthz # Health check → "OK"
curl http://localhost:8080/version # Build version (JSON)
curl "http://localhost:8080/api/echo?msg=hello" # Echo API
curl http://localhost:8080/metrics # Prometheus metricsAll settings are configurable via environment variables. No config files needed:
| Variable | Default | Description |
|---|---|---|
SERVER_PORT |
8080 |
Listen port |
LIMIT_PER_SEC |
20000 |
Max requests per second |
READ_TIMEOUT |
30s |
Request read timeout |
WRITE_TIMEOUT |
30s |
Response write timeout |
IDLE_TIMEOUT |
120s |
Keep-alive idle timeout |
SHUTDOWN_TIMEOUT |
30s |
Graceful shutdown deadline |
MAX_CONNS_PER_IP |
10000 |
Per-IP connection limit |
MAX_REQS_PER_CONN |
1000 |
Requests per connection |
Example:
SERVER_PORT=9000 LIMIT_PER_SEC=50000 ./microfast-servermicrofast/
├── cmd/server/main.go # Entry point
├── config/ # Environment-based configuration
├── internal/
│ ├── handler/ # Route handlers + Prometheus metrics
│ ├── middleware/ # Composable middleware chain
│ ├── limiter/ # Lock-free rate limiter (atomic CAS)
│ ├── logger/ # Structured logging (zap)
│ └── server/ # Server lifecycle & graceful shutdown
├── pkg/version/ # Build-time version injection
├── scripts/bench.go # Load testing tool
├── openapi.yaml # OpenAPI 3.0 spec
├── Makefile # Build, test, lint, docker commands
└── dockerfile # Multi-stage scratch image
make build # Build binary
make build-version # Build with version injectionmake test # Run tests with race detector
make bench # Run benchmarks
make lint # Run golangci-lintmake docker-build # Build Docker image
make docker-run # Run in containerThe request pipeline is fully composable:
Request → Recovery → RequestID → Logging → RateLimit → SecureHeaders → CORS → Handler
Each middleware is an independent function — add, remove, or reorder freely in internal/server/server.go.
Built-in load generator:
# Start server first, then:
go run scripts/bench.go
# Or use wrk / hey:
wrk -t8 -c1000 -d10s http://localhost:8080/
hey -n 100000 -c 500 http://localhost:8080/healthzSee openapi.yaml for the full OpenAPI 3.0 specification.
Preview it live at Swagger Editor.
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Welcome page |
/healthz |
GET | Health check (for K8s probes) |
/version |
GET | Build version (JSON) |
/api/echo |
GET | Echo ?msg= back as JSON |
/metrics |
GET | Prometheus metrics |
Contributions are welcome! See CONTRIBUTING.md for guidelines.
To report a vulnerability, see SECURITY.md.
MIT © 命本如此
⭐ Star this repo if you find it useful!