aboutsummaryrefslogtreecommitdiff
path: root/internal/api/run.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/run.go')
-rw-r--r--internal/api/run.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/api/run.go b/internal/api/run.go
new file mode 100644
index 0000000..0bd8a9b
--- /dev/null
+++ b/internal/api/run.go
@@ -0,0 +1,24 @@
+package api
+
+import (
+ "context"
+ "errors"
+ "net/http"
+)
+
+// Run starts the HTTP server and blocks until it exits.
+func (s *Server) Run(ctx context.Context) error {
+ go func() {
+ <-ctx.Done()
+
+ _ = s.http.Shutdown(context.Background())
+ }()
+
+ err := s.http.ListenAndServe()
+
+ if errors.Is(err, http.ErrServerClosed) {
+ return nil
+ }
+
+ return err
+}