diff --git a/engine/engine.go b/engine/engine.go index 9fe339519..dab5f2387 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -6,7 +6,8 @@ import ( "time" "github.com/labstack/gommon/log" - "net") + "net" +) type ( // Engine defines the interface for HTTP server. @@ -17,9 +18,6 @@ type ( // SetLogger sets the logger for the HTTP server. SetLogger(*log.Logger) - // SetListener sets custom listener for the HTTP server. - SetListener(net.Listener) - // Start starts the HTTP server. Start() } @@ -140,6 +138,7 @@ type ( // Config defines engine configuration. Config struct { Address string // TCP address to listen on. + Listener net.Listener // Custom net.Listener for the HTTP server. TLSCertfile string // TLS certificate file path. TLSKeyfile string // TLS key file path. ReadTimeout time.Duration // Maximum duration before timing out read of the request. diff --git a/engine/fasthttp/server.go b/engine/fasthttp/server.go index a768f48be..ee0957d43 100644 --- a/engine/fasthttp/server.go +++ b/engine/fasthttp/server.go @@ -9,17 +9,15 @@ import ( "github.com/labstack/echo/engine" "github.com/labstack/gommon/log" "github.com/valyala/fasthttp" - "net" ) type ( // Server implements `engine.Engine`. Server struct { - config engine.Config - handler engine.Handler - listener net.Listener - logger *log.Logger - pool *pool + config engine.Config + handler engine.Handler + logger *log.Logger + pool *pool } pool struct { @@ -91,11 +89,6 @@ func (s *Server) SetHandler(h engine.Handler) { s.handler = h } -// SetHandler implements `engine.Engine#SetListener` method. -func (s *Server) SetListener(ln net.Listener) { - s.listener = ln -} - // SetLogger implements `engine.Engine#SetLogger` method. func (s *Server) SetLogger(l *log.Logger) { s.logger = l @@ -131,7 +124,7 @@ func (s *Server) Start() { certfile := s.config.TLSCertfile keyfile := s.config.TLSKeyfile - if nil == s.listener { + if nil == s.config.Listener { s.startDefaultListener(addr, certfile, keyfile, handler) } else { s.startCustomListener(certfile, keyfile, handler) @@ -148,9 +141,9 @@ func (s *Server) startDefaultListener(addr, certfile, keyfile string, handler fu func (s *Server) startCustomListener(certfile, keyfile string, handler func(c *fasthttp.RequestCtx)) { if certfile != "" && keyfile != "" { - s.logger.Fatal(fasthttp.ServeTLS(s.listener, certfile, keyfile, handler)) + s.logger.Fatal(fasthttp.ServeTLS(s.config.Listener, certfile, keyfile, handler)) } else { - s.logger.Fatal(fasthttp.Serve(s.listener, handler)) + s.logger.Fatal(fasthttp.Serve(s.config.Listener, handler)) } } diff --git a/engine/standard/server.go b/engine/standard/server.go index 06945cf0a..717146e0a 100644 --- a/engine/standard/server.go +++ b/engine/standard/server.go @@ -7,18 +7,16 @@ import ( "github.com/labstack/echo" "github.com/labstack/echo/engine" "github.com/labstack/gommon/log" - "net" ) type ( // Server implements `engine.Engine`. Server struct { *http.Server - config engine.Config - handler engine.Handler - listener net.Listener - logger *log.Logger - pool *pool + config engine.Config + handler engine.Handler + logger *log.Logger + pool *pool } pool struct { @@ -87,11 +85,6 @@ func (s *Server) SetHandler(h engine.Handler) { s.handler = h } -// SetHandler implements `engine.Engine#SetListener` method. -func (s *Server) SetListener(ln net.Listener) { - s.listener = ln -} - // SetLogger implements `engine.Engine#SetLogger` method. func (s *Server) SetLogger(l *log.Logger) { s.logger = l @@ -102,7 +95,7 @@ func (s *Server) Start() { certfile := s.config.TLSCertfile keyfile := s.config.TLSKeyfile - if nil == s.listener { + if nil == s.config.Listener { s.startDefaultListener(certfile, keyfile) } else { s.startCustomListener() @@ -118,7 +111,7 @@ func (s *Server) startDefaultListener(certfile, keyfile string) { } func (s *Server) startCustomListener() { - s.logger.Fatal(s.Serve(s.listener)) + s.logger.Fatal(s.Serve(s.config.Listener)) } // ServeHTTP implements `http.Handler` interface.