about summary refs log tree commit diff
path: root/tvix/nar-bridge/pkg/server/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/nar-bridge/pkg/server/server.go')
-rw-r--r--tvix/nar-bridge/pkg/server/server.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/tvix/nar-bridge/pkg/server/server.go b/tvix/nar-bridge/pkg/server/server.go
index 0de38c84dfee..f58842bfa792 100644
--- a/tvix/nar-bridge/pkg/server/server.go
+++ b/tvix/nar-bridge/pkg/server/server.go
@@ -1,6 +1,7 @@
 package server
 
 import (
+	"context"
 	"fmt"
 	"net/http"
 	"sync"
@@ -13,6 +14,7 @@ import (
 )
 
 type Server struct {
+	srv     *http.Server
 	handler chi.Router
 
 	directoryServiceClient storev1pb.DirectoryServiceClient
@@ -73,8 +75,14 @@ func New(
 	return s
 }
 
+func (s *Server) Shutdown(ctx context.Context) error {
+	return s.srv.Shutdown(ctx)
+}
+
+// ListenAndServer starts the webserver, and waits for it being closed or
+// shutdown, after which it'll return ErrServerClosed.
 func (s *Server) ListenAndServe(addr string) error {
-	srv := &http.Server{
+	s.srv = &http.Server{
 		Addr:         addr,
 		Handler:      s.handler,
 		ReadTimeout:  500 * time.Second,
@@ -82,5 +90,5 @@ func (s *Server) ListenAndServe(addr string) error {
 		IdleTimeout:  500 * time.Second,
 	}
 
-	return srv.ListenAndServe()
+	return s.srv.ListenAndServe()
 }