diff --git a/go.mod b/go.mod index 4f3a793e..bd9d287e 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.22 require ( github.com/beevik/ntp v1.4.3 github.com/prometheus/client_golang v1.19.1 - github.com/sapcc/go-api-declarations v1.12.0 - github.com/sapcc/go-bits v0.0.0-20240725082021-261f0bf53c79 + github.com/sapcc/go-api-declarations v1.12.1 + github.com/sapcc/go-bits v0.0.0-20240801093859-8ef04d19f38d go.uber.org/automaxprocs v1.5.3 ) diff --git a/go.sum b/go.sum index df05f36a..eca7386b 100644 --- a/go.sum +++ b/go.sum @@ -22,10 +22,10 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/sapcc/go-api-declarations v1.12.0 h1:lFgLbufRQ+rZOaJctF0Tw+6KWYvtRhnpVimtaNzc2So= -github.com/sapcc/go-api-declarations v1.12.0/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI= -github.com/sapcc/go-bits v0.0.0-20240725082021-261f0bf53c79 h1:+UVZQpUPdlDoKyiAQ5SgvE/zxQ1AF/hlan+wD8V1Qqg= -github.com/sapcc/go-bits v0.0.0-20240725082021-261f0bf53c79/go.mod h1:AWYXw+xIyaouPyJj6s1M66t/Txw0r0ft6X5Pgljg/R0= +github.com/sapcc/go-api-declarations v1.12.1 h1:1/QfRD7D4OGfZv3F1HGFwwAJtiuYUvjqE/XhE4UnpCc= +github.com/sapcc/go-api-declarations v1.12.1/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI= +github.com/sapcc/go-bits v0.0.0-20240801093859-8ef04d19f38d h1:J6hg859uZMKn3aEQhEZBdUMXvbKIl3I7t7kNM4qeOps= +github.com/sapcc/go-bits v0.0.0-20240801093859-8ef04d19f38d/go.mod h1:GDqhmlHFdWGzbJlpNinE2f21GOvOKe5tt2N1rOix4I0= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/vendor/github.com/sapcc/go-bits/httpext/server.go b/vendor/github.com/sapcc/go-bits/httpext/server.go index 379582aa..c9e99038 100644 --- a/vendor/github.com/sapcc/go-bits/httpext/server.go +++ b/vendor/github.com/sapcc/go-bits/httpext/server.go @@ -72,7 +72,18 @@ func ContextWithSIGINT(ctx context.Context, delay time.Duration) context.Context func ListenAndServeContext(ctx context.Context, addr string, handler http.Handler) error { logg.Info("Listening on %s...", addr) server := &http.Server{Addr: addr, Handler: handler} + return listenAndServeContext(ctx, server, func() error { return server.ListenAndServe() }) +} + +// ListenAndServeTLSContext is a wrapper around http.ListenAndServeTLS() that additionally +// shuts down the HTTP server gracefully when the context expires, or if an error occurs. +func ListenAndServeTLSContext(ctx context.Context, addr, certFile, keyFile string, handler http.Handler) error { + logg.Info("Listening on %s...", addr) + server := &http.Server{Addr: addr, Handler: handler} + return listenAndServeContext(ctx, server, func() error { return server.ListenAndServeTLS(certFile, keyFile) }) +} +func listenAndServeContext(ctx context.Context, server *http.Server, listenAndServe func() error) error { // waitForServerShutdown channel serves two purposes: // 1. It is used to block until server.Shutdown() returns to prevent // program from exiting prematurely. This is because when Shutdown is @@ -95,13 +106,13 @@ func ListenAndServeContext(ctx context.Context, addr string, handler http.Handle waitForServerShutdown <- err }() - listenAndServeErr := server.ListenAndServe() - if listenAndServeErr != http.ErrServerClosed { + listenAndServeErr := listenAndServe() + if listenAndServeErr != http.ErrServerClosed { //nolint:errorlint // errorlint usually understands that this error is returned directly from ListenAndServe(), but the indirection confuses it shutdownServer <- struct{}{} } shutdownErr := <-waitForServerShutdown - if listenAndServeErr == http.ErrServerClosed { + if listenAndServeErr == http.ErrServerClosed { //nolint:errorlint // same as above return addPrefix(shutdownErr, "ListenAndServeContext: could not shutdown HTTP server") } diff --git a/vendor/modules.txt b/vendor/modules.txt index 54204dd5..f6813b57 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -27,10 +27,10 @@ github.com/prometheus/common/model github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/sapcc/go-api-declarations v1.12.0 +# github.com/sapcc/go-api-declarations v1.12.1 ## explicit; go 1.21 github.com/sapcc/go-api-declarations/bininfo -# github.com/sapcc/go-bits v0.0.0-20240725082021-261f0bf53c79 +# github.com/sapcc/go-bits v0.0.0-20240801093859-8ef04d19f38d ## explicit; go 1.22 github.com/sapcc/go-bits/httpext github.com/sapcc/go-bits/logg