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

Minor changes in router

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-04-03 15:40:36 -07:00
parent 05d52420be
commit d0f44c90ba
4 changed files with 16 additions and 6 deletions

View File

@ -38,6 +38,7 @@ func (c *Context) Bind(i interface{}) (err error) {
if err = dec.Decode(i); err != nil {
err = ErrBindJSON
}
} else if strings.HasPrefix(ct, MIMEForm) {
} else {
err = ErrUnsupportedContentType
}

View File

@ -35,8 +35,10 @@ const (
MethodPUT = "PUT"
MethodTRACE = "TRACE"
MIMEJSON = "application/json"
MIMEText = "text/plain"
MIMEJSON = "application/json"
MIMEText = "text/plain"
MIMEForm = "application/x-www-form-urlencoded"
MIMEMultipartForm = "multipart/form-data"
HeaderAccept = "Accept"
HeaderContentDisposition = "Content-Disposition"

View File

@ -167,6 +167,7 @@ func (r *router) Find(method, path string) (h HandlerFunc, c *Context, echo *Ech
for {
if search == "" || search == cn.prefix {
// Found
h = cn.handler
echo = cn.echo
return
@ -210,10 +211,8 @@ func (r *router) Find(method, path string) (h HandlerFunc, c *Context, echo *Ech
}
cn = e
continue
} else {
// Not found
return
}
return
}
}

View File

@ -57,9 +57,17 @@ func TestRouterMicroParam(t *testing.T) {
}
}
func TestRouterConflict(t *testing.T) {
r := New().Router
r.Add("GET", "/users/new", func(*Context) {}, nil)
r.Add("GET", "/users/wen", func(*Context) {}, nil)
r.Add("GET", "/users/:id", func(*Context) {}, nil)
r.trees["GET"].printTree("", true)
}
func (n *node) printTree(pfx string, tail bool) {
p := prefix(tail, pfx, "└── ", "├── ")
fmt.Printf("%s%s has=%d, h=%v, eid=%d\n", p, n.prefix, n.has, n.handler, n.echo)
fmt.Printf("%s%s has=%d, h=%v, echo=%d\n", p, n.prefix, n.has, n.handler, n.echo)
nodes := n.edges
l := len(nodes)