Skip to content

Commit

Permalink
dummy
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Mar 18, 2016
1 parent bf239af commit 7cf31b3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"mime/multipart"
"time"

"github.com/labstack/gommon/log"
"net"

"github.com/labstack/gommon/log"
)

type (
Expand Down Expand Up @@ -138,7 +139,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.
Listener net.Listener // Custom `net.Listener`. If set, server accepts connections on it.
TLSCertfile string // TLS certificate file path.
TLSKeyfile string // TLS key file path.
ReadTimeout time.Duration // Maximum duration before timing out read of the request.
Expand Down
14 changes: 7 additions & 7 deletions engine/fasthttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,26 @@ func (s *Server) Start() {
certfile := s.config.TLSCertfile
keyfile := s.config.TLSKeyfile

if nil == s.config.Listener {
if s.config.Listener == nil {
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)) {
func (s *Server) startDefaultListener(addr, certfile, keyfile string, h fasthttp.RequestHandler) {
if certfile != "" && keyfile != "" {
s.logger.Fatal(fasthttp.ListenAndServeTLS(addr, certfile, keyfile, handler))
s.logger.Fatal(fasthttp.ListenAndServeTLS(addr, certfile, keyfile, h))
} else {
s.logger.Fatal(fasthttp.ListenAndServe(addr, handler))
s.logger.Fatal(fasthttp.ListenAndServe(addr, h))
}
}

func (s *Server) startCustomListener(certfile, keyfile string, handler func(c *fasthttp.RequestCtx)) {
func (s *Server) startCustomListener(certfile, keyfile string, h fasthttp.RequestHandler) {
if certfile != "" && keyfile != "" {
s.logger.Fatal(fasthttp.ServeTLS(s.config.Listener, certfile, keyfile, handler))
s.logger.Fatal(fasthttp.ServeTLS(s.config.Listener, certfile, keyfile, h))
} else {
s.logger.Fatal(fasthttp.Serve(s.config.Listener, handler))
s.logger.Fatal(fasthttp.Serve(s.config.Listener, h))
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/standard/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *Server) Start() {
certfile := s.config.TLSCertfile
keyfile := s.config.TLSKeyfile

if nil == s.config.Listener {
if s.config.Listener == nil {
s.startDefaultListener(certfile, keyfile)
} else {
s.startCustomListener()
Expand Down
7 changes: 6 additions & 1 deletion router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ func TestRouterAPI(t *testing.T) {
func BenchmarkRouterGitHubAPI(b *testing.B) {
e := New()
r := e.router
b.ReportAllocs()

// Add routes
for _, route := range api {
Expand All @@ -584,10 +585,14 @@ func BenchmarkRouterGitHubAPI(b *testing.B) {
}

// Find routes
c := e.pool.Get().(*context)
for i := 0; i < b.N; i++ {
for _, route := range api {
// c := e.pool.Get().(*context)
c := e.GetContext()
r.Find(route.Method, route.Path, c)
// router.Find(r.Method, r.Path, c)
e.PutContext(c)
// e.pool.Put(c)
}
}
}
Expand Down

0 comments on commit 7cf31b3

Please sign in to comment.