httpserver depends on launcher (Tier 2), placing it at Tier 3. With launcher corrected from Tier 5 to Tier 2, httpserver's tier drops accordingly.
2.8 KiB
2.8 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
0.9.0 - 2026-03-18
Added
Loggerinterface — duck-typed; requiresInfo(msg string, args ...any)andError(msg string, err error, args ...any); satisfied directly bylogz.Loggerand by any two-method struct, with no import oflogzrequiredConfigstruct — holds HTTP server configuration with env-tag support:Host(SERVER_HOST, default0.0.0.0),Port(SERVER_PORT, default8080),ReadTimeout(SERVER_READ_TIMEOUT, default5s),WriteTimeout(SERVER_WRITE_TIMEOUT, default10s),IdleTimeout(SERVER_IDLE_TIMEOUT, default120s)Optionfunctional option type for configuring the server at construction timeWithMiddleware(mw ...func(http.Handler) http.Handler) Option— accumulates middleware applied to the root chi router duringOnInit; order is preserved and caller-controlled; multiple calls toWithMiddlewareappend to the listHttpServerComponentinterface — embeds bothlauncher.Componentandchi.Router, giving callers the complete chi routing API (Get,Post,Route,Mount,Use,With,Group, etc.) on the same value that participates in the launcher lifecycleNew(logger Logger, cfg Config, opts ...Option) HttpServerComponent— constructs the server component backed bychi.NewRouter(); no middleware is installed by defaultOnInitlifecycle method — applies all middleware registered viaWithMiddlewareto the root router; no-op if none were providedOnStartlifecycle method — constructs anhttp.Serverwith the configured timeouts and starts it in a background goroutine; logs the bind address on start and logs fatal errors ifListenAndServeexits unexpectedlyOnStoplifecycle method — callshttp.Server.Shutdownwith a 10-second context timeout, giving in-flight requests up to 10 seconds to complete before the method returns
Design Notes
HttpServerComponentembedschi.Routerdirectly in the interface rather than delegating through wrapper methods, so callers register routes and manage the lifecycle on the same value with no extra indirection- No middleware is installed by default; the full middleware stack is composed explicitly via
WithMiddlewareat construction time, keeping the stack visible and ordering unambiguous in the application source - chi was chosen as the underlying router because it uses stdlib
http.Handlerthroughout, making it fully compatible withhttpmwmiddleware andhttputilhandler adapters without any wrapper code at the boundary