diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c63a26..6f9fb3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this module will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.2] - 2026-05-12 + +### Added + +- `Config.ShutdownTimeout time.Duration` (`SERVER_SHUTDOWN_TIMEOUT`, default `10s`) — configures the graceful-shutdown deadline passed to `http.Server.Shutdown`. Previously hardcoded to 10 seconds; callers that serve long-running requests (uploads, streaming) or prefer a shorter fail-fast window can now set this per environment. + +### Changed + +- `launcher` and `logz` dependencies bumped from v0.9.0 to v1.0.1. +- `go` directive updated from 1.25 to 1.26. + ## [0.9.2] - 2026-03-25 ### Fixed @@ -44,6 +55,7 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0. - No middleware is installed by default; the full middleware stack is composed explicitly via `WithMiddleware` at 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.Handler` throughout, making it fully compatible with `httpmw` middleware and `httputil` handler adapters without any wrapper code at the boundary +[1.0.2]: https://code.nochebuena.dev/go/httpserver/releases/tag/v1.0.2 [0.9.2]: https://code.nochebuena.dev/go/httpserver/releases/tag/v0.9.2 [0.9.1]: https://code.nochebuena.dev/go/httpserver/releases/tag/v0.9.1 [0.9.0]: https://code.nochebuena.dev/go/httpserver/releases/tag/v0.9.0 diff --git a/go.mod b/go.mod index b6854b0..709c340 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module code.nochebuena.dev/go/httpserver -go 1.25 +go 1.26 require ( - code.nochebuena.dev/go/launcher v0.9.0 + code.nochebuena.dev/go/launcher v1.0.1 github.com/go-chi/chi/v5 v5.2.1 ) -require code.nochebuena.dev/go/logz v0.9.0 // indirect +require code.nochebuena.dev/go/logz v1.0.1 // indirect diff --git a/go.sum b/go.sum index 2b986f8..b36390f 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ -code.nochebuena.dev/go/launcher v0.9.0 h1:dJHonA9Xm03AQKK0919FJaQn9ZKHZ+RZfB9yxjnx3TA= -code.nochebuena.dev/go/launcher v0.9.0/go.mod h1:IBtntmbnyddukjEhxlc7Ysdzz9nZsnd9+8FzAIHt77g= -code.nochebuena.dev/go/logz v0.9.0 h1:wfV7vtI4V/8ED7Hm31Fbql7Y5iOGrlHN4X8Z5ajTZZE= -code.nochebuena.dev/go/logz v0.9.0/go.mod h1:qODhSbKb+tWE7rdhHLcKweiP5CgwIaWoZxadCT3bQV8= +code.nochebuena.dev/go/launcher v1.0.1 h1:hbPV8jNtyxfchrT7igzz3M2tKGI3bm8uWkHBXRvSPgg= +code.nochebuena.dev/go/launcher v1.0.1/go.mod h1:1KwndVuqm31JN9Dpl9YvOmlogPlKKzoDMo9aRFkYwmM= +code.nochebuena.dev/go/logz v1.0.1 h1:kK9aZo19L208CwCr2D/dbSOMaOv62cXsigMSsdFu+8Y= +code.nochebuena.dev/go/logz v1.0.1/go.mod h1:YNpNm03fURm2v0ySh/477z9AJhtfRcd9rFOW6fFqgNM= github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8= github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= diff --git a/httpserver.go b/httpserver.go index e0481ea..7c1841b 100644 --- a/httpserver.go +++ b/httpserver.go @@ -21,11 +21,12 @@ type Logger interface { // Config holds the HTTP server configuration. 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"` + 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"` + ShutdownTimeout time.Duration `env:"SERVER_SHUTDOWN_TIMEOUT" envDefault:"10s"` } // serverOpts holds functional options. @@ -125,7 +126,11 @@ func (s *httpServer) OnStop() error { return nil } s.logger.Info("httpserver: shutting down gracefully") - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + timeout := s.cfg.ShutdownTimeout + if timeout == 0 { + timeout = 10 * time.Second + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() return s.srv.Shutdown(ctx) }