1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +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 b3e9b66e36
commit 50f89c394e
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) {
e := New()
// func(*echo.Context) error
e.Get("/1", func(c *Context) {
c.String(http.StatusOK, "1")
})
// HandlerFunc
e.Get("/1", HandlerFunc(func(c *Context) error {
return c.String(http.StatusOK, "1")
}))
w := httptest.NewRecorder()
r, _ := http.NewRequest(GET, "/1", nil)
e.ServeHTTP(w, r)
@ -132,9 +132,9 @@ func TestEchoHandler(t *testing.T) {
t.Error("body should be 1")
}
// HandlerFunc
e.Get("/2", func(c *Context) {
c.String(http.StatusOK, "2")
// func(*echo.Context) error
e.Get("/2", func(c *Context) error {
return c.String(http.StatusOK, "2")
})
w = httptest.NewRecorder()
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
for {
// TODO flip condition???
if search == "" || search == cn.prefix || cn.typ == mtype {
// Found
h = cn.handler
echo = cn.echo
ctx.pnames = cn.pnames
// Match-any
// Match-any node
if cn.typ == mtype {
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)
data structure which makes routing lookup really fast. It leverages
[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
below registers a route for method `GET`, path `/hello` and a handler which sends
@ -167,7 +167,7 @@ with status code.
### 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.
### HTML