From 3fb9c66ffa0bf87cbd7cc1b5f4129f3447e94c13 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Wed, 1 May 2024 20:27:00 +0200 Subject: feat: Initial http server code --- pkg/worker/http.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pkg/worker/http.go (limited to 'pkg/worker/http.go') 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) +} -- cgit v1.2.3