diff --git a/go.mod b/go.mod index 35ba044..8f80573 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/gophercloud/gophercloud/v2 v2.1.0 github.com/gophercloud/utils/v2 v2.0.0-20240725072607-4241c98875fa 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 github.com/spf13/cobra v1.8.1 go.uber.org/automaxprocs v1.5.3 ) diff --git a/go.sum b/go.sum index 80bc57b..2bc10fa 100644 --- a/go.sum +++ b/go.sum @@ -41,10 +41,10 @@ github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoG github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -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/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= diff --git a/vendor/github.com/sapcc/go-bits/httpext/server.go b/vendor/github.com/sapcc/go-bits/httpext/server.go index 379582a..c9e9903 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 5ecb2b5..bc01071 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -56,10 +56,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