beego: update the router rule for *
* not match the empty route
Showing
4 changed files
with
4 additions
and
7 deletions
| ... | @@ -381,9 +381,11 @@ func initBeforeHttpRun() { | ... | @@ -381,9 +381,11 @@ func initBeforeHttpRun() { |
| 381 | middleware.RegisterErrorHandler() | 381 | middleware.RegisterErrorHandler() |
| 382 | 382 | ||
| 383 | for u, _ := range StaticDir { | 383 | for u, _ := range StaticDir { |
| 384 | Get(u, serverStaticRouter) | ||
| 384 | Get(u+"/*", serverStaticRouter) | 385 | Get(u+"/*", serverStaticRouter) |
| 385 | } | 386 | } |
| 386 | if EnableDocs { | 387 | if EnableDocs { |
| 388 | Get("/docs", serverDocs) | ||
| 387 | Get("/docs/*", serverDocs) | 389 | Get("/docs/*", serverDocs) |
| 388 | } | 390 | } |
| 389 | } | 391 | } | ... | ... |
| ... | @@ -350,9 +350,11 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) | ... | @@ -350,9 +350,11 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) |
| 350 | route.methods = map[string]string{"*": rt.Method(i).Name} | 350 | route.methods = map[string]string{"*": rt.Method(i).Name} |
| 351 | route.controllerType = ct | 351 | route.controllerType = ct |
| 352 | pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") | 352 | pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") |
| 353 | patternfix := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name)) | ||
| 353 | route.pattern = pattern | 354 | route.pattern = pattern |
| 354 | for _, m := range HTTPMETHOD { | 355 | for _, m := range HTTPMETHOD { |
| 355 | p.addToRouter(m, pattern, route) | 356 | p.addToRouter(m, pattern, route) |
| 357 | p.addToRouter(m, patternfix, route) | ||
| 356 | } | 358 | } |
| 357 | } | 359 | } |
| 358 | } | 360 | } | ... | ... |
| ... | @@ -267,12 +267,6 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string | ... | @@ -267,12 +267,6 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string |
| 267 | } | 267 | } |
| 268 | return true, params | 268 | return true, params |
| 269 | } | 269 | } |
| 270 | if len(leaf.wildcards) == 1 && leaf.wildcards[0] == ":splat" { | ||
| 271 | params = make(map[string]string) | ||
| 272 | params[":splat"] = "" | ||
| 273 | return true, params | ||
| 274 | } | ||
| 275 | Error("bug of router") | ||
| 276 | return false, nil | 270 | return false, nil |
| 277 | } else if len(wildcardValues) == 0 { // static path | 271 | } else if len(wildcardValues) == 0 { // static path |
| 278 | return true, nil | 272 | return true, nil | ... | ... |
| ... | @@ -18,7 +18,6 @@ func init() { | ... | @@ -18,7 +18,6 @@ func init() { |
| 18 | routers = append(routers, testinfo{"/customer/login", "/customer/login", nil}) | 18 | routers = append(routers, testinfo{"/customer/login", "/customer/login", nil}) |
| 19 | routers = append(routers, testinfo{"/customer/login", "/customer/login.json", map[string]string{":ext": "json"}}) | 19 | routers = append(routers, testinfo{"/customer/login", "/customer/login.json", map[string]string{":ext": "json"}}) |
| 20 | routers = append(routers, testinfo{"/*", "/customer/123", map[string]string{":splat": "customer/123"}}) | 20 | routers = append(routers, testinfo{"/*", "/customer/123", map[string]string{":splat": "customer/123"}}) |
| 21 | routers = append(routers, testinfo{"/customer/*", "/customer", map[string]string{":splat": ""}}) | ||
| 22 | routers = append(routers, testinfo{"/*", "/customer/2009/12/11", map[string]string{":splat": "customer/2009/12/11"}}) | 21 | routers = append(routers, testinfo{"/*", "/customer/2009/12/11", map[string]string{":splat": "customer/2009/12/11"}}) |
| 23 | routers = append(routers, testinfo{"/*.*", "/nice/api.json", map[string]string{":path": "nice/api", ":ext": "json"}}) | 22 | routers = append(routers, testinfo{"/*.*", "/nice/api.json", map[string]string{":path": "nice/api", ":ext": "json"}}) |
| 24 | routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) | 23 | routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) | ... | ... |
-
Please register or sign in to post a comment