diff --git a/rest/internal/starter.go b/rest/internal/starter.go index 1fcff7f3..735775e9 100644 --- a/rest/internal/starter.go +++ b/rest/internal/starter.go @@ -12,7 +12,8 @@ import ( func StartHttp(host string, port int, handler http.Handler) error { addr := fmt.Sprintf("%s:%d", host, port) server := buildHttpServer(addr, handler) - return StartServer(server) + gracefulOnShutdown(server) + return server.ListenAndServe() } func StartHttps(host string, port int, certFile, keyFile string, handler http.Handler) error { @@ -20,18 +21,12 @@ func StartHttps(host string, port int, certFile, keyFile string, handler http.Ha if server, err := buildHttpsServer(addr, handler, certFile, keyFile); err != nil { return err } else { - return StartServer(server) + gracefulOnShutdown(server) + // certFile and keyFile are set in buildHttpsServer + return server.ListenAndServeTLS("", "") } } -func StartServer(srv *http.Server) error { - proc.AddWrapUpListener(func() { - srv.Shutdown(context.Background()) - }) - - return srv.ListenAndServe() -} - func buildHttpServer(addr string, handler http.Handler) *http.Server { return &http.Server{Addr: addr, Handler: handler} } @@ -49,3 +44,9 @@ func buildHttpsServer(addr string, handler http.Handler, certFile, keyFile strin TLSConfig: &config, }, nil } + +func gracefulOnShutdown(srv *http.Server) { + proc.AddWrapUpListener(func() { + srv.Shutdown(context.Background()) + }) +}