microfast

module
v0.0.0-...-a1d1f9a Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT

README ΒΆ

⚑ microfast

A blazing-fast, production-ready HTTP server built with Go and fasthttp.

CI Go Report Card License Go Reference


Why microfast?

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

Quick Start

Prerequisites

  • Go 1.22+ (tested with 1.23)

Install & Run

git clone https://github.com/888zxc/microfast.git
cd microfast
make run

That's it. The server is now running on http://localhost:8080.

Try It

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 metrics

Configuration

All 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-server

Project Structure

microfast/
β”œβ”€β”€ 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

Development

Build

make build                    # Build binary
make build-version            # Build with version injection

Test

make test                     # Run tests with race detector
make bench                    # Run benchmarks
make lint                     # Run golangci-lint

Docker

make docker-build             # Build Docker image
make docker-run               # Run in container

Middleware Stack

The 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.


Benchmarking

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/healthz

API Reference

See 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

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Security

To report a vulnerability, see SECURITY.md.

License

MIT Β© ε‘½ζœ¬ε¦‚ζ­€


⭐ Star this repo if you find it useful!

Directories ΒΆ

Path Synopsis
cmd
server command
internal
pkg

Jump to

Keyboard shortcuts

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