mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
Engine standard > http.Server as private field
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
f4a5abc8b2
commit
6ed0b57228
@ -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{
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user