Commit f6c7a6bd authored by astaxie's avatar astaxie

beego: improve the admin router print

parent d2eece9a
......@@ -122,17 +122,29 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
case "router":
fmt.Fprintln(rw, "Print all router infomation:")
for _, router := range BeeApp.Handlers.fixrouters {
if router.hasMethod {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
} else {
fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name())
if router.routerType == routerTypeBeego {
if router.hasMethod {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
} else {
fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name())
}
} else if router.routerType == routerTypeRESTFul {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.runfunction)
} else if router.routerType == routerTypeHandler {
fmt.Fprintln(rw, router.pattern, "----", router.handler)
}
}
for _, router := range BeeApp.Handlers.routers {
if router.hasMethod {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
} else {
fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name())
if router.routerType == routerTypeBeego {
if router.hasMethod {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
} else {
fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name())
}
} else if router.routerType == routerTypeRESTFul {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.runfunction)
} else if router.routerType == routerTypeHandler {
fmt.Fprintln(rw, router.pattern, "----", router.handler)
}
}
if BeeApp.Handlers.enableAuto {
......
......@@ -525,7 +525,7 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
}
controllName := strings.Join(paths[:len(paths)-1], ".")
methodName := paths[len(paths)-1]
for _, route := range p.fixrouters {
for _, route := range p.routers {
if route.controllerType.Name() == controllName {
var finded bool
if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) {
......@@ -550,13 +550,27 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
if !finded {
continue
}
if len(values) > 0 {
return route.pattern + "?" + urlv.Encode()
var returnurl string
var i int
var startreg bool
for _, v := range route.regex.String() {
if v == '(' {
startreg = true
continue
} else if v == ')' {
startreg = false
returnurl = returnurl + urlv.Get(route.params[i])
i++
} else if !startreg {
returnurl = string(append([]rune(returnurl), v))
}
}
if route.regex.MatchString(returnurl) {
return returnurl
}
return route.pattern
}
}
for _, route := range p.routers {
for _, route := range p.fixrouters {
if route.controllerType.Name() == controllName {
var finded bool
if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) {
......@@ -581,24 +595,10 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
if !finded {
continue
}
var returnurl string
var i int
var startreg bool
for _, v := range route.regex.String() {
if v == '(' {
startreg = true
continue
} else if v == ')' {
startreg = false
returnurl = returnurl + urlv.Get(route.params[i])
i++
} else if !startreg {
returnurl = string(append([]rune(returnurl), v))
}
}
if route.regex.MatchString(returnurl) {
return returnurl
if len(values) > 0 {
return route.pattern + "?" + urlv.Encode()
}
return route.pattern
}
}
if p.enableAuto {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment