httpserver
Lifecycle-managed HTTP server built on chi that integrates with the launcher component model.
Features
- Implements
launcher.Component (OnInit / OnStart / OnStop)
- Embeds
chi.Router — full routing API exposed directly on the component
- Graceful shutdown with configurable timeouts
- No middleware installed by default — compose your stack with
WithMiddleware
Installation
Usage
Config
| Field |
Env var |
Default |
Description |
Host |
SERVER_HOST |
0.0.0.0 |
Bind address |
Port |
SERVER_PORT |
8080 |
Listen port |
ReadTimeout |
SERVER_READ_TIMEOUT |
5s |
Max time to read request |
WriteTimeout |
SERVER_WRITE_TIMEOUT |
10s |
Max time to write response |
IdleTimeout |
SERVER_IDLE_TIMEOUT |
120s |
Keep-alive idle timeout |
Options
| Option |
Description |
WithMiddleware(mw ...func(http.Handler) http.Handler) |
Applies middleware to the root router during OnInit |
Lifecycle
| Phase |
Action |
OnInit |
Applies registered middleware to the router |
OnStart |
Starts net/http.Server in a background goroutine |
OnStop |
Graceful shutdown — waits up to 10s for in-flight requests |