diff options
Diffstat (limited to 'pkg/worker/http.go')
-rw-r--r-- | pkg/worker/http.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/worker/http.go b/pkg/worker/http.go new file mode 100644 index 0000000..1d56f86 --- /dev/null +++ b/pkg/worker/http.go @@ -0,0 +1,26 @@ +package worker + +import ( + "context" + "net/http" +) + +type ServerTask struct { + server *http.Server +} + +func NewServerTask(server *http.Server) *ServerTask { + return &ServerTask{ + server: server, + } +} + +func (self *ServerTask) Start(ctx context.Context) error { + go func() { + // nolint: errcheck + self.server.ListenAndServe() + }() + + <-ctx.Done() + return self.server.Shutdown(ctx) +} |