Skip to content

Commit

Permalink
Exclude fasthttp in appengine
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
Vishal Rana committed Feb 9, 2016
1 parent 4982169 commit bf97da9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 30 deletions.
25 changes: 6 additions & 19 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"encoding/xml"

"github.com/labstack/echo/engine"
"github.com/labstack/echo/engine/fasthttp"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/logger"
"github.com/labstack/gommon/log"
Expand All @@ -37,8 +36,6 @@ type (
debug bool
hook engine.HandlerFunc
autoIndex bool
engineType engine.Type
engine engine.Engine
router *Router
logger logger.Logger
}
Expand Down Expand Up @@ -514,7 +511,7 @@ func (e *Echo) Routes() []Route {
return e.router.routes
}

func (e *Echo) handle(req engine.Request, res engine.Response) {
func (e *Echo) Handle(req engine.Request, res engine.Response) {
if e.hook != nil {
e.hook(req, res)
}
Expand Down Expand Up @@ -546,14 +543,10 @@ func (e *Echo) handle(req engine.Request, res engine.Response) {
// return s
// }

func (e *Echo) SetEngine(t engine.Type) {
e.engineType = t
}

// Run runs a server.
func (e *Echo) Run(addr string) {
c := &engine.Config{Address: addr}
e.RunConfig(c)
e.RunEngine(standard.NewServer(c, e.Handle, e.logger))
}

// RunTLS runs a server with TLS configuration.
Expand All @@ -563,18 +556,12 @@ func (e *Echo) RunTLS(addr, certfile, keyfile string) {
TLSCertfile: certfile,
TLSKeyfile: keyfile,
}
e.RunConfig(c)
e.RunEngine(standard.NewServer(c, e.Handle, e.logger))
}

// RunConfig runs a server with engine configuration.
func (e *Echo) RunConfig(config *engine.Config) {
switch e.engineType {
case engine.FastHTTP:
e.engine = fasthttp.NewServer(config, e.handle, e.logger)
default:
e.engine = standard.NewServer(config, e.handle, e.logger)
}
e.engine.Start()
// RunEngine runs a custom engine.
func (*Echo) RunEngine(e engine.Engine) {
e.Start()
}

func NewHTTPError(code int, msg ...string) *HTTPError {
Expand Down
8 changes: 4 additions & 4 deletions echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func TestEchoNotFound(t *testing.T) {
e := New()
req := test.NewRequest(GET, "/files", nil)
rec := test.NewResponseRecorder()
e.handle(req, rec)
e.Handle(req, rec)
assert.Equal(t, http.StatusNotFound, rec.Status())
}

Expand All @@ -319,7 +319,7 @@ func TestEchoMethodNotAllowed(t *testing.T) {
})
req := test.NewRequest(POST, "/", nil)
rec := test.NewResponseRecorder()
e.handle(req, rec)
e.Handle(req, rec)
assert.Equal(t, http.StatusMethodNotAllowed, rec.Status())
}

Expand Down Expand Up @@ -350,7 +350,7 @@ func TestEchoHook(t *testing.T) {
})
req := test.NewRequest(GET, "/test/", nil)
rec := test.NewResponseRecorder()
e.handle(req, rec)
e.Handle(req, rec)
assert.Equal(t, req.URL().Path(), "/test")
}

Expand All @@ -371,6 +371,6 @@ func testMethod(t *testing.T, method, path string, e *Echo) {
func request(method, path string, e *Echo) (int, string) {
req := test.NewRequest(method, path, nil)
rec := test.NewResponseRecorder()
e.handle(req, rec)
e.Handle(req, rec)
return rec.Status(), rec.Body.String()
}
7 changes: 0 additions & 7 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
)

type (
Type uint8

HandlerFunc func(Request, Response)

Engine interface {
Expand Down Expand Up @@ -64,8 +62,3 @@ type (
TLSKeyfile string
}
)

const (
Standard Type = iota
FastHTTP
)
2 changes: 2 additions & 0 deletions engine/fasthttp/header.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package fasthttp

import "github.com/valyala/fasthttp"
Expand Down
2 changes: 2 additions & 0 deletions engine/fasthttp/request.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package fasthttp

import (
Expand Down
2 changes: 2 additions & 0 deletions engine/fasthttp/response.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package fasthttp

import (
Expand Down
2 changes: 2 additions & 0 deletions engine/fasthttp/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package fasthttp

import (
Expand Down
2 changes: 2 additions & 0 deletions engine/fasthttp/url.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package fasthttp

import "github.com/valyala/fasthttp"
Expand Down

0 comments on commit bf97da9

Please sign in to comment.