mirror of
https://github.com/labstack/echo.git
synced 2025-01-24 03:16:14 +02:00
parent
a88c4399d4
commit
1dcb7ba9ab
5
group.go
5
group.go
@ -16,6 +16,11 @@ type (
|
|||||||
// Use implements `Echo#Use()` for sub-routes within the Group.
|
// Use implements `Echo#Use()` for sub-routes within the Group.
|
||||||
func (g *Group) Use(m ...MiddlewareFunc) {
|
func (g *Group) Use(m ...MiddlewareFunc) {
|
||||||
g.middleware = append(g.middleware, m...)
|
g.middleware = append(g.middleware, m...)
|
||||||
|
// Allow all requests to reach the group as they might get dropped if router
|
||||||
|
// doesn't find a match, making none of the group middleware process.
|
||||||
|
g.echo.Any(g.prefix+"*", func(c Context) error {
|
||||||
|
return ErrNotFound
|
||||||
|
}, g.middleware...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group.
|
// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group.
|
||||||
|
@ -343,7 +343,7 @@ func (r *Router) Find(method, path string, context Context) {
|
|||||||
// Static node
|
// Static node
|
||||||
if c = cn.findChild(search[0], skind); c != nil {
|
if c = cn.findChild(search[0], skind); c != nil {
|
||||||
// Save next
|
// Save next
|
||||||
if cn.label == '/' {
|
if cn.prefix[len(cn.prefix)-1] == '/' { // Issue #623
|
||||||
nk = pkind
|
nk = pkind
|
||||||
nn = cn
|
nn = cn
|
||||||
ns = search
|
ns = search
|
||||||
@ -361,7 +361,7 @@ func (r *Router) Find(method, path string, context Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save next
|
// Save next
|
||||||
if cn.label == '/' {
|
if cn.prefix[len(cn.prefix)-1] == '/' { // Issue #623
|
||||||
nk = akind
|
nk = akind
|
||||||
nn = cn
|
nn = cn
|
||||||
ns = search
|
ns = search
|
||||||
|
@ -552,6 +552,38 @@ func TestRouterParamNames(t *testing.T) {
|
|||||||
assert.Equal(t, "1", c.P(1))
|
assert.Equal(t, "1", c.P(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #623
|
||||||
|
func TestRouterStaticDynamicConflict(t *testing.T) {
|
||||||
|
e := New()
|
||||||
|
r := e.router
|
||||||
|
c := e.NewContext(nil, nil)
|
||||||
|
|
||||||
|
r.Add(GET, "/dictionary/skills", func(c Context) error {
|
||||||
|
c.Set("a", 1)
|
||||||
|
return nil
|
||||||
|
}, e)
|
||||||
|
r.Add(GET, "/dictionary/:name", func(c Context) error {
|
||||||
|
c.Set("b", 2)
|
||||||
|
return nil
|
||||||
|
}, e)
|
||||||
|
r.Add(GET, "/server", func(c Context) error {
|
||||||
|
c.Set("c", 3)
|
||||||
|
return nil
|
||||||
|
}, e)
|
||||||
|
|
||||||
|
r.Find(GET, "/dictionary/skills", c)
|
||||||
|
c.Handler()(c)
|
||||||
|
assert.Equal(t, 1, c.Get("a"))
|
||||||
|
c = e.NewContext(nil, nil)
|
||||||
|
r.Find(GET, "/dictionary/type", c)
|
||||||
|
c.Handler()(c)
|
||||||
|
assert.Equal(t, 2, c.Get("b"))
|
||||||
|
c = e.NewContext(nil, nil)
|
||||||
|
r.Find(GET, "/server", c)
|
||||||
|
c.Handler()(c)
|
||||||
|
assert.Equal(t, 3, c.Get("c"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestRouterAPI(t *testing.T) {
|
func TestRouterAPI(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
r := e.router
|
r := e.router
|
||||||
|
Loading…
x
Reference in New Issue
Block a user