Documentation
¶
Overview ¶
Package httpserver provides a lifecycle-managed HTTP server built on chi.
It implements launcher.Component so it integrates directly with the launcher lifecycle (OnInit → OnStart → OnStop). It also embeds chi.Router, giving callers the full chi routing API: Get, Post, Route, Mount, Use, etc.
No middleware is installed by default. Compose your stack with WithMiddleware:
srv := httpserver.New(logger, cfg,
httpserver.WithMiddleware(
httpmw.Recover(),
httpmw.CORS([]string{"*"}),
httpmw.RequestID(uuid.NewString),
httpmw.RequestLogger(logger),
),
)
srv.Get("/health", healthHandler)
srv.Route("/api/v1", func(r chi.Router) { ... })
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string `env:"SERVER_HOST" envDefault:"0.0.0.0"`
Port int `env:"SERVER_PORT" envDefault:"8080"`
ReadTimeout time.Duration `env:"SERVER_READ_TIMEOUT" envDefault:"5s"`
WriteTimeout time.Duration `env:"SERVER_WRITE_TIMEOUT" envDefault:"10s"`
IdleTimeout time.Duration `env:"SERVER_IDLE_TIMEOUT" envDefault:"120s"`
}
Config holds the HTTP server configuration.
type HttpServerComponent ¶
HttpServerComponent is a launcher.Component that also exposes a chi.Router. Embedding chi.Router gives callers the full routing API: Get, Post, Route, Mount, Use, etc.
func New ¶
func New(logger Logger, cfg Config, opts ...Option) HttpServerComponent
New creates an HttpServerComponent. No middleware is installed by default; use WithMiddleware to compose the middleware stack.