A production-style HTTP service written in Go, demonstrating idiomatic project structure, middleware, observability, and graceful shutdown.
This project is designed as a learning and reference implementation for building cloud-native backend services.
- ⚡ HTTP server with routing
- 🧩 Middleware chain (logging + request ID)
- 📊 Metrics endpoint
- 🪵 Structured logging
- 🧵 Request tracing via context
- 🐳 Docker support
- 🛑 Graceful shutdown
- 🗂️ Idiomatic Go project layout
.
├── cmd/server # Application entrypoint
│ └── main.go
│
├── internal
│ ├── http # HTTP layer (router, middleware, handlers)
│ ├── observability # Logging, metrics, request IDs
│ └── config # Configuration management
│
├── Dockerfile
├── go.mod
└── README.md
- Go ≥ 1.25
- (Optional) Docker
go run ./cmd/serverServer starts on:
http://localhost:8080
GET /health
Response:
200 OK
GET /metrics
Example output:
requests_total 5
uptime_seconds 42
The server reads configuration from environment variables.
| Variable | Default | Description |
|---|---|---|
PORT |
8080 |
Server port |
Example:
PORT=9090 go run ./cmd/serverBuild image:
docker build -t go-http-server .Run container:
docker run -p 8080:8080 go-http-serverThis service implements the three pillars of observability:
- Logs → structured request logs
- Tracing → request IDs
- Metrics →
/metricsendpoint
The server listens for system signals (SIGINT, SIGTERM) and shuts down gracefully:
- stops accepting new requests
- allows in-flight requests to finish
- exits cleanly
Run the server:
go run ./cmd/serverFormat code:
go fmt ./...This project demonstrates:
- Idiomatic Go project structure
- Middleware design
- Context propagation
- Service lifecycle management
- Observability patterns
Contributions are welcome!
Feel free to open issues or submit pull requests.
MIT License