1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-26 20:54:00 +02:00

Minor changes

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-04-29 11:22:07 -07:00
parent 4068674a0b
commit 2330dd27a7
3 changed files with 11 additions and 10 deletions

View File

@ -121,10 +121,10 @@ func TestEchoMiddleware(t *testing.T) {
func TestEchoHandler(t *testing.T) { func TestEchoHandler(t *testing.T) {
e := New() e := New()
// func(*echo.Context) error // HandlerFunc
e.Get("/1", func(c *Context) { e.Get("/1", HandlerFunc(func(c *Context) error {
c.String(http.StatusOK, "1") return c.String(http.StatusOK, "1")
}) }))
w := httptest.NewRecorder() w := httptest.NewRecorder()
r, _ := http.NewRequest(GET, "/1", nil) r, _ := http.NewRequest(GET, "/1", nil)
e.ServeHTTP(w, r) e.ServeHTTP(w, r)
@ -132,9 +132,9 @@ func TestEchoHandler(t *testing.T) {
t.Error("body should be 1") t.Error("body should be 1")
} }
// HandlerFunc // func(*echo.Context) error
e.Get("/2", func(c *Context) { e.Get("/2", func(c *Context) error {
c.String(http.StatusOK, "2") return c.String(http.StatusOK, "2")
}) })
w = httptest.NewRecorder() w = httptest.NewRecorder()
r, _ = http.NewRequest(GET, "/2", nil) r, _ = http.NewRequest(GET, "/2", nil)

View File

@ -227,13 +227,14 @@ func (r *router) Find(method, path string, ctx *Context) (h HandlerFunc, echo *E
// Search order static > param > match-any // Search order static > param > match-any
for { for {
// TODO flip condition???
if search == "" || search == cn.prefix || cn.typ == mtype { if search == "" || search == cn.prefix || cn.typ == mtype {
// Found // Found
h = cn.handler h = cn.handler
echo = cn.echo echo = cn.echo
ctx.pnames = cn.pnames ctx.pnames = cn.pnames
// Match-any // Match-any node
if cn.typ == mtype { if cn.typ == mtype {
ctx.pvalues[0] = search[len(cn.prefix):] ctx.pvalues[0] = search[len(cn.prefix):]
} }

View File

@ -58,7 +58,7 @@ Echo's router is [fast, optimized](https://github.com/labstack/echo#benchmark) a
flexible. It's based on [redix tree](http://en.wikipedia.org/wiki/Radix_tree) flexible. It's based on [redix tree](http://en.wikipedia.org/wiki/Radix_tree)
data structure which makes routing lookup really fast. It leverages data structure which makes routing lookup really fast. It leverages
[sync pool](https://golang.org/pkg/sync/#Pool) to reuse memory and achieve [sync pool](https://golang.org/pkg/sync/#Pool) to reuse memory and achieve
zero dynamic memory allocation with no garbage collection. zero dynamic memory allocation with no GC overhead.
Routes can be registered for any HTTP method, path and handler. For example, code Routes can be registered for any HTTP method, path and handler. For example, code
below registers a route for method `GET`, path `/hello` and a handler which sends below registers a route for method `GET`, path `/hello` and a handler which sends
@ -167,7 +167,7 @@ with status code.
### String ### String
`context.String(code int, s string) error` can be used to send plain text response `context.String(code int, s string) error` can be used to send a text/plain response
with status code. with status code.
### HTML ### HTML