aboutsummaryrefslogtreecommitdiff
path: root/internal/api/run.go
blob: 0bd8a9b514de2b8a7d5bfe836c38986f8b0a162a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}