From c4d8e4a244588330a4f658d41852ce9c89735f19 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 4 Nov 2014 15:29:33 +0800 Subject: [PATCH] fix #759 --- router.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/router.go b/router.go index 9b11be53..4a4a934b 100644 --- a/router.go +++ b/router.go @@ -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 } }