aboutsummaryrefslogtreecommitdiff
path: root/pkg/worker/httpserver.go
blob: dc8f255f1953dfec7011e4611dd54ddfb3d22cfa (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
25
26
package worker

import (
	"context"
	"net/http"
)

type ServerWorker struct {
	server *http.Server
}

func (self *ServerWorker) Start(ctx context.Context) error {
	go func() {
		// nolint: errcheck
		self.server.ListenAndServe()
	}()

	<-ctx.Done()
	return self.server.Shutdown(ctx)
}

func NewServerWorker(server *http.Server) *ServerWorker {
	return &ServerWorker{
		server: server,
	}
}