mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:00:54 +00:00
camel name style
This commit is contained in:
parent
30b80cba92
commit
475feb7e24
38
router.go
38
router.go
@ -510,10 +510,10 @@ func (p *ControllerRegister) URLFor(endpoint string, values ...interface{}) stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
controllName := strings.Join(paths[:len(paths)-1], "/")
|
controllerName := strings.Join(paths[:len(paths)-1], "/")
|
||||||
methodName := paths[len(paths)-1]
|
methodName := paths[len(paths)-1]
|
||||||
for m, t := range p.routers {
|
for m, t := range p.routers {
|
||||||
ok, url := p.geturl(t, "/", controllName, methodName, params, m)
|
ok, url := p.getUrl(t, "/", controllerName, methodName, params, m)
|
||||||
if ok {
|
if ok {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
@ -521,17 +521,17 @@ func (p *ControllerRegister) URLFor(endpoint string, values ...interface{}) stri
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName string, params map[string]string, httpMethod string) (bool, string) {
|
func (p *ControllerRegister) getUrl(t *Tree, url, controllerName, methodName string, params map[string]string, httpMethod string) (bool, string) {
|
||||||
for _, subtree := range t.fixrouters {
|
for _, subtree := range t.fixrouters {
|
||||||
u := path.Join(url, subtree.prefix)
|
u := path.Join(url, subtree.prefix)
|
||||||
ok, u := p.geturl(subtree, u, controllName, methodName, params, httpMethod)
|
ok, u := p.getUrl(subtree, u, controllerName, methodName, params, httpMethod)
|
||||||
if ok {
|
if ok {
|
||||||
return ok, u
|
return ok, u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t.wildcard != nil {
|
if t.wildcard != nil {
|
||||||
u := path.Join(url, urlPlaceholder)
|
u := path.Join(url, urlPlaceholder)
|
||||||
ok, u := p.geturl(t.wildcard, u, controllName, methodName, params, httpMethod)
|
ok, u := p.getUrl(t.wildcard, u, controllerName, methodName, params, httpMethod)
|
||||||
if ok {
|
if ok {
|
||||||
return ok, u
|
return ok, u
|
||||||
}
|
}
|
||||||
@ -539,7 +539,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
for _, l := range t.leaves {
|
for _, l := range t.leaves {
|
||||||
if c, ok := l.runObject.(*ControllerInfo); ok {
|
if c, ok := l.runObject.(*ControllerInfo); ok {
|
||||||
if c.routerType == routerTypeBeego &&
|
if c.routerType == routerTypeBeego &&
|
||||||
strings.HasSuffix(path.Join(c.controllerType.PkgPath(), c.controllerType.Name()), controllName) {
|
strings.HasSuffix(path.Join(c.controllerType.PkgPath(), c.controllerType.Name()), controllerName) {
|
||||||
find := false
|
find := false
|
||||||
if HTTPMETHOD[strings.ToUpper(methodName)] {
|
if HTTPMETHOD[strings.ToUpper(methodName)] {
|
||||||
if len(c.methods) == 0 {
|
if len(c.methods) == 0 {
|
||||||
@ -578,18 +578,18 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
canskip := false
|
canSkip := false
|
||||||
for _, v := range l.wildcards {
|
for _, v := range l.wildcards {
|
||||||
if v == ":" {
|
if v == ":" {
|
||||||
canskip = true
|
canSkip = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if u, ok := params[v]; ok {
|
if u, ok := params[v]; ok {
|
||||||
delete(params, v)
|
delete(params, v)
|
||||||
url = strings.Replace(url, urlPlaceholder, u, 1)
|
url = strings.Replace(url, urlPlaceholder, u, 1)
|
||||||
} else {
|
} else {
|
||||||
if canskip {
|
if canSkip {
|
||||||
canskip = false
|
canSkip = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return false, ""
|
return false, ""
|
||||||
@ -598,27 +598,27 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
return true, url + toURL(params)
|
return true, url + toURL(params)
|
||||||
}
|
}
|
||||||
var i int
|
var i int
|
||||||
var startreg bool
|
var startReg bool
|
||||||
regurl := ""
|
regUrl := ""
|
||||||
for _, v := range strings.Trim(l.regexps.String(), "^$") {
|
for _, v := range strings.Trim(l.regexps.String(), "^$") {
|
||||||
if v == '(' {
|
if v == '(' {
|
||||||
startreg = true
|
startReg = true
|
||||||
continue
|
continue
|
||||||
} else if v == ')' {
|
} else if v == ')' {
|
||||||
startreg = false
|
startReg = false
|
||||||
if v, ok := params[l.wildcards[i]]; ok {
|
if v, ok := params[l.wildcards[i]]; ok {
|
||||||
delete(params, l.wildcards[i])
|
delete(params, l.wildcards[i])
|
||||||
regurl = regurl + v
|
regUrl = regUrl + v
|
||||||
i++
|
i++
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else if !startreg {
|
} else if !startReg {
|
||||||
regurl = string(append([]rune(regurl), v))
|
regUrl = string(append([]rune(regUrl), v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if l.regexps.MatchString(regurl) {
|
if l.regexps.MatchString(regUrl) {
|
||||||
ps := strings.Split(regurl, "/")
|
ps := strings.Split(regUrl, "/")
|
||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
url = strings.Replace(url, urlPlaceholder, p, 1)
|
url = strings.Replace(url, urlPlaceholder, p, 1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user