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:
parent
05d52420be
commit
d0f44c90ba
@ -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
|
||||
}
|
||||
|
6
echo.go
6
echo.go
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user