From 6ed0b5722849e57e75adeabc386276ad7c31f09d Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Tue, 8 Mar 2016 08:44:13 -0800 Subject: [PATCH] Engine standard > http.Server as private field Signed-off-by: Vishal Rana --- engine/fasthttp/server.go | 8 ++++---- engine/standard/server.go | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/engine/fasthttp/server.go b/engine/fasthttp/server.go index 8c069ddd..9a70b01e 100644 --- a/engine/fasthttp/server.go +++ b/engine/fasthttp/server.go @@ -30,19 +30,19 @@ type ( func New(addr string) *Server { c := &engine.Config{Address: addr} - return NewConfig(c) + return NewWithConfig(c) } -func NewTLS(addr, certfile, keyfile string) *Server { +func NewWithTLS(addr, certfile, keyfile string) *Server { c := &engine.Config{ Address: addr, TLSCertfile: certfile, TLSKeyfile: keyfile, } - return NewConfig(c) + return NewWithConfig(c) } -func NewConfig(c *engine.Config) (s *Server) { +func NewWithConfig(c *engine.Config) (s *Server) { s = &Server{ config: c, pool: &Pool{ diff --git a/engine/standard/server.go b/engine/standard/server.go index 1acb1f6b..c152eaeb 100644 --- a/engine/standard/server.go +++ b/engine/standard/server.go @@ -11,7 +11,7 @@ import ( type ( Server struct { - *http.Server + server *http.Server config *engine.Config handler engine.Handler pool *Pool @@ -28,21 +28,21 @@ type ( func New(addr string) *Server { c := &engine.Config{Address: addr} - return NewConfig(c) + return NewWithConfig(c) } -func NewTLS(addr, certfile, keyfile string) *Server { +func NewWithTLS(addr, certfile, keyfile string) *Server { c := &engine.Config{ Address: addr, TLSCertfile: certfile, TLSKeyfile: keyfile, } - return NewConfig(c) + return NewWithConfig(c) } -func NewConfig(c *engine.Config) (s *Server) { +func NewWithConfig(c *engine.Config) (s *Server) { s = &Server{ - Server: new(http.Server), + server: new(http.Server), config: c, pool: &Pool{ request: sync.Pool{ @@ -83,14 +83,14 @@ func (s *Server) SetLogger(l *log.Logger) { } func (s *Server) Start() { - s.Addr = s.config.Address - s.Handler = s + s.server.Addr = s.config.Address + s.server.Handler = s certfile := s.config.TLSCertfile keyfile := s.config.TLSKeyfile if certfile != "" && keyfile != "" { - s.logger.Fatal(s.ListenAndServeTLS(certfile, keyfile)) + s.logger.Fatal(s.server.ListenAndServeTLS(certfile, keyfile)) } else { - s.logger.Fatal(s.ListenAndServe()) + s.logger.Fatal(s.server.ListenAndServe()) } } @@ -118,6 +118,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.pool.header.Put(resHdr) } +func (s *Server) Server() *http.Server { + return s.server +} + // WrapHandler wraps `http.Handler` into `echo.HandlerFunc`. func WrapHandler(h http.Handler) echo.HandlerFunc { return func(c echo.Context) error {