mirror of
https://github.com/labstack/echo.git
synced 2025-03-25 21:38:56 +02:00
Merge branch 'fix_missing_net_listener' of https://github.com/mtojek/echo into mtojek-fix_missing_net_listener
This commit is contained in:
commit
bf239af966
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/gommon/log"
|
"github.com/labstack/gommon/log"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -137,6 +138,7 @@ type (
|
|||||||
// Config defines engine configuration.
|
// Config defines engine configuration.
|
||||||
Config struct {
|
Config struct {
|
||||||
Address string // TCP address to listen on.
|
Address string // TCP address to listen on.
|
||||||
|
Listener net.Listener // Custom net.Listener for the HTTP server.
|
||||||
TLSCertfile string // TLS certificate file path.
|
TLSCertfile string // TLS certificate file path.
|
||||||
TLSKeyfile string // TLS key file path.
|
TLSKeyfile string // TLS key file path.
|
||||||
ReadTimeout time.Duration // Maximum duration before timing out read of the request.
|
ReadTimeout time.Duration // Maximum duration before timing out read of the request.
|
||||||
|
@ -123,6 +123,15 @@ func (s *Server) Start() {
|
|||||||
addr := s.config.Address
|
addr := s.config.Address
|
||||||
certfile := s.config.TLSCertfile
|
certfile := s.config.TLSCertfile
|
||||||
keyfile := s.config.TLSKeyfile
|
keyfile := s.config.TLSKeyfile
|
||||||
|
|
||||||
|
if nil == s.config.Listener {
|
||||||
|
s.startDefaultListener(addr, certfile, keyfile, handler)
|
||||||
|
} else {
|
||||||
|
s.startCustomListener(certfile, keyfile, handler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) startDefaultListener(addr, certfile, keyfile string, handler func(c *fasthttp.RequestCtx)) {
|
||||||
if certfile != "" && keyfile != "" {
|
if certfile != "" && keyfile != "" {
|
||||||
s.logger.Fatal(fasthttp.ListenAndServeTLS(addr, certfile, keyfile, handler))
|
s.logger.Fatal(fasthttp.ListenAndServeTLS(addr, certfile, keyfile, handler))
|
||||||
} else {
|
} else {
|
||||||
@ -130,6 +139,14 @@ func (s *Server) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) startCustomListener(certfile, keyfile string, handler func(c *fasthttp.RequestCtx)) {
|
||||||
|
if certfile != "" && keyfile != "" {
|
||||||
|
s.logger.Fatal(fasthttp.ServeTLS(s.config.Listener, certfile, keyfile, handler))
|
||||||
|
} else {
|
||||||
|
s.logger.Fatal(fasthttp.Serve(s.config.Listener, handler))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WrapHandler wraps `fasthttp.RequestHandler` into `echo.HandlerFunc`.
|
// WrapHandler wraps `fasthttp.RequestHandler` into `echo.HandlerFunc`.
|
||||||
func WrapHandler(h fasthttp.RequestHandler) echo.HandlerFunc {
|
func WrapHandler(h fasthttp.RequestHandler) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
|
@ -94,6 +94,15 @@ func (s *Server) SetLogger(l *log.Logger) {
|
|||||||
func (s *Server) Start() {
|
func (s *Server) Start() {
|
||||||
certfile := s.config.TLSCertfile
|
certfile := s.config.TLSCertfile
|
||||||
keyfile := s.config.TLSKeyfile
|
keyfile := s.config.TLSKeyfile
|
||||||
|
|
||||||
|
if nil == s.config.Listener {
|
||||||
|
s.startDefaultListener(certfile, keyfile)
|
||||||
|
} else {
|
||||||
|
s.startCustomListener()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) startDefaultListener(certfile, keyfile string) {
|
||||||
if certfile != "" && keyfile != "" {
|
if certfile != "" && keyfile != "" {
|
||||||
s.logger.Fatal(s.ListenAndServeTLS(certfile, keyfile))
|
s.logger.Fatal(s.ListenAndServeTLS(certfile, keyfile))
|
||||||
} else {
|
} else {
|
||||||
@ -101,6 +110,10 @@ func (s *Server) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) startCustomListener() {
|
||||||
|
s.logger.Fatal(s.Serve(s.config.Listener))
|
||||||
|
}
|
||||||
|
|
||||||
// ServeHTTP implements `http.Handler` interface.
|
// ServeHTTP implements `http.Handler` interface.
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Request
|
// Request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user