feat(httpserver): promote to v1.0.2 — configurable ShutdownTimeout, bump deps to v1.0.1, go 1.26
Add Config.ShutdownTimeout (SERVER_SHUTDOWN_TIMEOUT, default 10s) so callers can configure the graceful-shutdown deadline without code changes. Previously hardcoded to 10 seconds. Bump launcher and logz from v0.9.0 to v1.0.1, update go directive from 1.25 to 1.26. API committed as stable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user