From c8e1328164e9ffbd681c3c0e449f1e6b9856b896 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sun, 26 Feb 2023 19:54:48 +0100 Subject: feat: Inicial commit It contains rough template for the server and runners. It contains rough template for the server and runners. --- pkg/worker/httpserver.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pkg/worker/httpserver.go (limited to 'pkg/worker/httpserver.go') diff --git a/pkg/worker/httpserver.go b/pkg/worker/httpserver.go new file mode 100644 index 0000000..181cf73 --- /dev/null +++ b/pkg/worker/httpserver.go @@ -0,0 +1,31 @@ +package worker + +import ( + "context" + + "github.com/valyala/fasthttp" +) + +type ServerWorker struct { + server *fasthttp.Server +} + +func (self *ServerWorker) Start(ctx context.Context) error { + go func() { + // nolint: errcheck + self.server.ListenAndServe("0.0.0.0:8080") + }() + + <-ctx.Done() + return self.Shutdown() +} + +func (self *ServerWorker) Shutdown() error { + return self.server.Shutdown() +} + +func NewServerWorker(server *fasthttp.Server) *ServerWorker { + return &ServerWorker{ + server: server, + } +} -- cgit v1.2.3