mirror of
https://github.com/astaxie/beego.git
synced 2025-07-03 16:40:18 +00:00
beego: update licence& fix #669
This commit is contained in:
36
router.go
36
router.go
@ -1,13 +1,12 @@
|
||||
// Beego (http://beego.me/)
|
||||
|
||||
//
|
||||
// @description beego is an open-source, high-performance web framework for the Go programming language.
|
||||
|
||||
//
|
||||
// @link http://github.com/astaxie/beego for the canonical source repository
|
||||
|
||||
//
|
||||
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
||||
|
||||
//
|
||||
// @authors astaxie
|
||||
|
||||
package beego
|
||||
|
||||
import (
|
||||
@ -66,6 +65,8 @@ var (
|
||||
"DelSession", "SessionRegenerateID", "DestroySession", "IsAjax", "GetSecureCookie",
|
||||
"SetSecureCookie", "XsrfToken", "CheckXsrfCookie", "XsrfFormHtml",
|
||||
"GetControllerAndAction"}
|
||||
|
||||
url_placeholder = "{{placeholder}}"
|
||||
)
|
||||
|
||||
// To append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter
|
||||
@ -428,6 +429,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
||||
}
|
||||
}
|
||||
if t.wildcard != nil {
|
||||
url = path.Join(url, url_placeholder)
|
||||
ok, u := p.geturl(t.wildcard, url, controllName, methodName, params)
|
||||
if ok {
|
||||
return ok, u
|
||||
@ -456,15 +458,14 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
||||
if find {
|
||||
if l.regexps == nil {
|
||||
if len(l.wildcards) == 0 {
|
||||
return true, url
|
||||
return true, strings.Replace(url, "/"+url_placeholder, "", 1)
|
||||
}
|
||||
if len(l.wildcards) == 1 {
|
||||
if v, ok := params[l.wildcards[0]]; ok {
|
||||
delete(params, l.wildcards[0])
|
||||
return true, url + "/" + v + tourl(params)
|
||||
}
|
||||
if l.wildcards[0] == ":splat" {
|
||||
return true, url + tourl(params)
|
||||
return true, strings.Replace(url, url_placeholder, v, 1) + tourl(params)
|
||||
} else {
|
||||
return false, ""
|
||||
}
|
||||
}
|
||||
if len(l.wildcards) == 3 && l.wildcards[0] == "." {
|
||||
@ -472,7 +473,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
||||
if e, isok := params[":ext"]; isok {
|
||||
delete(params, ":path")
|
||||
delete(params, ":ext")
|
||||
return true, url + "/" + p + "." + e + tourl(params)
|
||||
return true, strings.Replace(url, url_placeholder, p+"."+e, -1) + tourl(params)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -483,7 +484,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
||||
continue
|
||||
}
|
||||
if u, ok := params[v]; ok {
|
||||
url += "/" + u
|
||||
delete(params, v)
|
||||
url = strings.Replace(url, url_placeholder, u, 1)
|
||||
} else {
|
||||
if canskip {
|
||||
canskip = false
|
||||
@ -493,7 +495,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
||||
}
|
||||
}
|
||||
}
|
||||
return true, url
|
||||
return true, url + tourl(params)
|
||||
} else {
|
||||
var i int
|
||||
var startreg bool
|
||||
@ -516,11 +518,11 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
||||
}
|
||||
}
|
||||
if l.regexps.MatchString(regurl) {
|
||||
if url == "/" {
|
||||
return true, url + regurl + tourl(params)
|
||||
} else {
|
||||
return true, url + "/" + regurl + tourl(params)
|
||||
ps := strings.Split(regurl, "/")
|
||||
for _, p := range ps {
|
||||
url = strings.Replace(url, url_placeholder, p, 1)
|
||||
}
|
||||
return true, url + tourl(params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user