From af4f153830ed90898ea1c3ff8d5790c243ecbe76 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 21 Jun 2014 11:44:24 +0800 Subject: [PATCH] beego: update the router rule for * * not match the empty route --- beego.go | 2 ++ router.go | 2 ++ tree.go | 6 ------ tree_test.go | 1 - 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/beego.go b/beego.go index 6a940563..06736c76 100644 --- a/beego.go +++ b/beego.go @@ -381,9 +381,11 @@ func initBeforeHttpRun() { middleware.RegisterErrorHandler() for u, _ := range StaticDir { + Get(u, serverStaticRouter) Get(u+"/*", serverStaticRouter) } if EnableDocs { + Get("/docs", serverDocs) Get("/docs/*", serverDocs) } } diff --git a/router.go b/router.go index 00c7f237..0041c273 100644 --- a/router.go +++ b/router.go @@ -350,9 +350,11 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) route.methods = map[string]string{"*": rt.Method(i).Name} route.controllerType = ct pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") + patternfix := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name)) route.pattern = pattern for _, m := range HTTPMETHOD { p.addToRouter(m, pattern, route) + p.addToRouter(m, patternfix, route) } } } diff --git a/tree.go b/tree.go index 10ebb428..991a120e 100644 --- a/tree.go +++ b/tree.go @@ -267,12 +267,6 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string } return true, params } - if len(leaf.wildcards) == 1 && leaf.wildcards[0] == ":splat" { - params = make(map[string]string) - params[":splat"] = "" - return true, params - } - Error("bug of router") return false, nil } else if len(wildcardValues) == 0 { // static path return true, nil diff --git a/tree_test.go b/tree_test.go index 991611f7..f1c37469 100644 --- a/tree_test.go +++ b/tree_test.go @@ -18,7 +18,6 @@ func init() { routers = append(routers, testinfo{"/customer/login", "/customer/login", nil}) routers = append(routers, testinfo{"/customer/login", "/customer/login.json", map[string]string{":ext": "json"}}) routers = append(routers, testinfo{"/*", "/customer/123", map[string]string{":splat": "customer/123"}}) - routers = append(routers, testinfo{"/customer/*", "/customer", map[string]string{":splat": ""}}) routers = append(routers, testinfo{"/*", "/customer/2009/12/11", map[string]string{":splat": "customer/2009/12/11"}}) routers = append(routers, testinfo{"/*.*", "/nice/api.json", map[string]string{":path": "nice/api", ":ext": "json"}}) routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}})