1
0
mirror of https://github.com/labstack/echo.git synced 2025-04-23 12:18:53 +02:00

Exclude fasthttp in appengine

Signed-off-by: Vishal Rana <vishal.rana@verizon.com>
This commit is contained in:
Vishal Rana 2016-02-09 11:43:00 -08:00
parent 4982169106
commit bf97da9a16
8 changed files with 20 additions and 30 deletions

25
echo.go
View File

@ -17,7 +17,6 @@ import (
"encoding/xml" "encoding/xml"
"github.com/labstack/echo/engine" "github.com/labstack/echo/engine"
"github.com/labstack/echo/engine/fasthttp"
"github.com/labstack/echo/engine/standard" "github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/logger" "github.com/labstack/echo/logger"
"github.com/labstack/gommon/log" "github.com/labstack/gommon/log"
@ -37,8 +36,6 @@ type (
debug bool debug bool
hook engine.HandlerFunc hook engine.HandlerFunc
autoIndex bool autoIndex bool
engineType engine.Type
engine engine.Engine
router *Router router *Router
logger logger.Logger logger logger.Logger
} }
@ -514,7 +511,7 @@ func (e *Echo) Routes() []Route {
return e.router.routes 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 { if e.hook != nil {
e.hook(req, res) e.hook(req, res)
} }
@ -546,14 +543,10 @@ func (e *Echo) handle(req engine.Request, res engine.Response) {
// return s // return s
// } // }
func (e *Echo) SetEngine(t engine.Type) {
e.engineType = t
}
// Run runs a server. // Run runs a server.
func (e *Echo) Run(addr string) { func (e *Echo) Run(addr string) {
c := &engine.Config{Address: addr} c := &engine.Config{Address: addr}
e.RunConfig(c) e.RunEngine(standard.NewServer(c, e.Handle, e.logger))
} }
// RunTLS runs a server with TLS configuration. // RunTLS runs a server with TLS configuration.
@ -563,18 +556,12 @@ func (e *Echo) RunTLS(addr, certfile, keyfile string) {
TLSCertfile: certfile, TLSCertfile: certfile,
TLSKeyfile: keyfile, TLSKeyfile: keyfile,
} }
e.RunConfig(c) e.RunEngine(standard.NewServer(c, e.Handle, e.logger))
} }
// RunConfig runs a server with engine configuration. // RunEngine runs a custom engine.
func (e *Echo) RunConfig(config *engine.Config) { func (*Echo) RunEngine(e engine.Engine) {
switch e.engineType { e.Start()
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()
} }
func NewHTTPError(code int, msg ...string) *HTTPError { func NewHTTPError(code int, msg ...string) *HTTPError {

View File

@ -308,7 +308,7 @@ func TestEchoNotFound(t *testing.T) {
e := New() e := New()
req := test.NewRequest(GET, "/files", nil) req := test.NewRequest(GET, "/files", nil)
rec := test.NewResponseRecorder() rec := test.NewResponseRecorder()
e.handle(req, rec) e.Handle(req, rec)
assert.Equal(t, http.StatusNotFound, rec.Status()) assert.Equal(t, http.StatusNotFound, rec.Status())
} }
@ -319,7 +319,7 @@ func TestEchoMethodNotAllowed(t *testing.T) {
}) })
req := test.NewRequest(POST, "/", nil) req := test.NewRequest(POST, "/", nil)
rec := test.NewResponseRecorder() rec := test.NewResponseRecorder()
e.handle(req, rec) e.Handle(req, rec)
assert.Equal(t, http.StatusMethodNotAllowed, rec.Status()) assert.Equal(t, http.StatusMethodNotAllowed, rec.Status())
} }
@ -350,7 +350,7 @@ func TestEchoHook(t *testing.T) {
}) })
req := test.NewRequest(GET, "/test/", nil) req := test.NewRequest(GET, "/test/", nil)
rec := test.NewResponseRecorder() rec := test.NewResponseRecorder()
e.handle(req, rec) e.Handle(req, rec)
assert.Equal(t, req.URL().Path(), "/test") assert.Equal(t, req.URL().Path(), "/test")
} }
@ -371,6 +371,6 @@ func testMethod(t *testing.T, method, path string, e *Echo) {
func request(method, path string, e *Echo) (int, string) { func request(method, path string, e *Echo) (int, string) {
req := test.NewRequest(method, path, nil) req := test.NewRequest(method, path, nil)
rec := test.NewResponseRecorder() rec := test.NewResponseRecorder()
e.handle(req, rec) e.Handle(req, rec)
return rec.Status(), rec.Body.String() return rec.Status(), rec.Body.String()
} }

View File

@ -6,8 +6,6 @@ import (
) )
type ( type (
Type uint8
HandlerFunc func(Request, Response) HandlerFunc func(Request, Response)
Engine interface { Engine interface {
@ -64,8 +62,3 @@ type (
TLSKeyfile string TLSKeyfile string
} }
) )
const (
Standard Type = iota
FastHTTP
)

View File

@ -1,3 +1,5 @@
// +build !appengine
package fasthttp package fasthttp
import "github.com/valyala/fasthttp" import "github.com/valyala/fasthttp"

View File

@ -1,3 +1,5 @@
// +build !appengine
package fasthttp package fasthttp
import ( import (

View File

@ -1,3 +1,5 @@
// +build !appengine
package fasthttp package fasthttp
import ( import (

View File

@ -1,3 +1,5 @@
// +build !appengine
package fasthttp package fasthttp
import ( import (

View File

@ -1,3 +1,5 @@
// +build !appengine
package fasthttp package fasthttp
import "github.com/valyala/fasthttp" import "github.com/valyala/fasthttp"