1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 12:10:55 +00:00
This commit is contained in:
astaxie 2014-11-04 15:29:33 +08:00
parent 9d4ec508bb
commit c4d8e4a244

View File

@ -452,8 +452,8 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
}
controllName := strings.Join(paths[:len(paths)-1], "/")
methodName := paths[len(paths)-1]
for _, t := range p.routers {
ok, url := p.geturl(t, "/", controllName, methodName, params)
for m, t := range p.routers {
ok, url := p.geturl(t, "/", controllName, methodName, params, m)
if ok {
return url
}
@ -461,17 +461,17 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
return ""
}
func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName string, params map[string]string) (bool, string) {
func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName string, params map[string]string, httpMethod string) (bool, string) {
for k, subtree := range t.fixrouters {
u := path.Join(url, k)
ok, u := p.geturl(subtree, u, controllName, methodName, params)
ok, u := p.geturl(subtree, u, controllName, methodName, params, httpMethod)
if ok {
return ok, u
}
}
if t.wildcard != nil {
url = path.Join(url, url_placeholder)
ok, u := p.geturl(t.wildcard, url, controllName, methodName, params)
u := path.Join(url, url_placeholder)
ok, u := p.geturl(t.wildcard, u, controllName, methodName, params, httpMethod)
if ok {
return ok, u
}
@ -491,8 +491,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
}
}
if !find {
for _, md := range c.methods {
if md == methodName {
for m, md := range c.methods {
if (m == "*" || m == httpMethod) && md == methodName {
find = true
}
}