mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 20:30:55 +00:00
improve router
This commit is contained in:
parent
d0cb112f4b
commit
3d481178d7
18
router.go
18
router.go
@ -383,13 +383,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
findrouter = true
|
findrouter = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// pattern /admin url /admin 200 /admin/ 404
|
||||||
if (requestPath[n-1] != '/' && route.pattern == requestPath) ||
|
// pattern /admin/ url /admin 301 /admin/ 200
|
||||||
(requestPath[n-1] == '/' && len(route.pattern) >= n-1 && requestPath[0:n-1] == route.pattern) ||
|
if requestPath[n-1] != '/' && len(route.pattern) == n+1 &&
|
||||||
(len(route.pattern) == n+1 && requestPath == route.pattern[0:n]) {
|
route.pattern[n] == '/' && route.pattern[:n-1] == requestPath {
|
||||||
runrouter = route
|
http.Redirect(w, r, requestPath+"/", 301)
|
||||||
findrouter = true
|
return
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,7 +544,10 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
if !findrouter {
|
if !findrouter {
|
||||||
for cName, methodmap := range p.autoRouter {
|
for cName, methodmap := range p.autoRouter {
|
||||||
if strings.HasPrefix(strings.ToLower(requestPath), "/"+cName) {
|
if strings.ToLower(requestPath) == "/"+cName+"/" {
|
||||||
|
requestPath = requestPath + "index"
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(strings.ToLower(requestPath), "/"+cName+"/") {
|
||||||
for mName, controllerType := range methodmap {
|
for mName, controllerType := range methodmap {
|
||||||
if strings.HasPrefix(strings.ToLower(requestPath), "/"+cName+"/"+strings.ToLower(mName)) {
|
if strings.HasPrefix(strings.ToLower(requestPath), "/"+cName+"/"+strings.ToLower(mName)) {
|
||||||
//parse params
|
//parse params
|
||||||
|
Loading…
Reference in New Issue
Block a user