c4d8e4a2 by astaxie

fix #759

1 parent 9d4ec508
...@@ -452,8 +452,8 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { ...@@ -452,8 +452,8 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
452 } 452 }
453 controllName := strings.Join(paths[:len(paths)-1], "/") 453 controllName := strings.Join(paths[:len(paths)-1], "/")
454 methodName := paths[len(paths)-1] 454 methodName := paths[len(paths)-1]
455 for _, t := range p.routers { 455 for m, t := range p.routers {
456 ok, url := p.geturl(t, "/", controllName, methodName, params) 456 ok, url := p.geturl(t, "/", controllName, methodName, params, m)
457 if ok { 457 if ok {
458 return url 458 return url
459 } 459 }
...@@ -461,17 +461,17 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { ...@@ -461,17 +461,17 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
461 return "" 461 return ""
462 } 462 }
463 463
464 func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName string, params map[string]string) (bool, string) { 464 func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName string, params map[string]string, httpMethod string) (bool, string) {
465 for k, subtree := range t.fixrouters { 465 for k, subtree := range t.fixrouters {
466 u := path.Join(url, k) 466 u := path.Join(url, k)
467 ok, u := p.geturl(subtree, u, controllName, methodName, params) 467 ok, u := p.geturl(subtree, u, controllName, methodName, params, httpMethod)
468 if ok { 468 if ok {
469 return ok, u 469 return ok, u
470 } 470 }
471 } 471 }
472 if t.wildcard != nil { 472 if t.wildcard != nil {
473 url = path.Join(url, url_placeholder) 473 u := path.Join(url, url_placeholder)
474 ok, u := p.geturl(t.wildcard, url, controllName, methodName, params) 474 ok, u := p.geturl(t.wildcard, u, controllName, methodName, params, httpMethod)
475 if ok { 475 if ok {
476 return ok, u 476 return ok, u
477 } 477 }
...@@ -491,8 +491,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin ...@@ -491,8 +491,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
491 } 491 }
492 } 492 }
493 if !find { 493 if !find {
494 for _, md := range c.methods { 494 for m, md := range c.methods {
495 if md == methodName { 495 if (m == "*" || m == httpMethod) && md == methodName {
496 find = true 496 find = true
497 } 497 }
498 } 498 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!