update server.go
This commit is contained in:
1 parent
2c169c7d4d
commit
61f48fd03c
1 file changed
+28
@@ -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)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user