From 61f48fd03c92d82710b07c49787175f44c2d0c40 Mon Sep 17 00:00:00 2001 From: Denis Istratov Date: Tue, 22 Oct 2024 12:00:00 +0300 Subject: [PATCH] update server.go --- server.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 server.go diff --git a/server.go b/server.go new file mode 100644 index 0000000..dc070cd --- /dev/null +++ b/server.go @@ -0,0 +1,28 @@ +package esproject + +import ( + "context" + "github.com/sirupsen/logrus" + "net/http" + "time" +) + +type Server struct { + httpServer *http.Server +} + +func (s *Server) Run(port string, handler http.Handler) error { + s.httpServer = &http.Server{ + Addr: ":" + port, + Handler: handler, + MaxHeaderBytes: 1 << 20, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + } + logrus.Info("running server...") + return s.httpServer.ListenAndServe() +} + +func (s *Server) Shutdown(ctx context.Context) error { + return s.httpServer.Shutdown(ctx) +}