mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
Exclude fasthttp in appengine
Signed-off-by: Vishal Rana <vishal.rana@verizon.com>
This commit is contained in:
parent
4982169106
commit
bf97da9a16
25
echo.go
25
echo.go
@ -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"
|
||||
@ -37,8 +36,6 @@ type (
|
||||
debug bool
|
||||
hook engine.HandlerFunc
|
||||
autoIndex bool
|
||||
engineType engine.Type
|
||||
engine engine.Engine
|
||||
router *Router
|
||||
logger logger.Logger
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
@ -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.
|
||||
@ -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 {
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
@ -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())
|
||||
}
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Type uint8
|
||||
|
||||
HandlerFunc func(Request, Response)
|
||||
|
||||
Engine interface {
|
||||
@ -64,8 +62,3 @@ type (
|
||||
TLSKeyfile string
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
Standard Type = iota
|
||||
FastHTTP
|
||||
)
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build !appengine
|
||||
|
||||
package fasthttp
|
||||
|
||||
import "github.com/valyala/fasthttp"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build !appengine
|
||||
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build !appengine
|
||||
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build !appengine
|
||||
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build !appengine
|
||||
|
||||
package fasthttp
|
||||
|
||||
import "github.com/valyala/fasthttp"
|
||||
|
Loading…
Reference in New Issue
Block a user