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) { ...@@ -122,17 +122,29 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
case "router": case "router":
fmt.Fprintln(rw, "Print all router infomation:") fmt.Fprintln(rw, "Print all router infomation:")
for _, router := range BeeApp.Handlers.fixrouters { for _, router := range BeeApp.Handlers.fixrouters {
if router.hasMethod { if router.routerType == routerTypeBeego {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name()) if router.hasMethod {
} else { fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
fmt.Fprintln(rw, router.pattern, "----", 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 { for _, router := range BeeApp.Handlers.routers {
if router.hasMethod { if router.routerType == routerTypeBeego {
fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name()) if router.hasMethod {
} else { fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
fmt.Fprintln(rw, router.pattern, "----", 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 { if BeeApp.Handlers.enableAuto {
......
...@@ -525,7 +525,7 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { ...@@ -525,7 +525,7 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
} }
controllName := strings.Join(paths[:len(paths)-1], ".") controllName := strings.Join(paths[:len(paths)-1], ".")
methodName := paths[len(paths)-1] methodName := paths[len(paths)-1]
for _, route := range p.fixrouters { for _, route := range p.routers {
if route.controllerType.Name() == controllName { if route.controllerType.Name() == controllName {
var finded bool var finded bool
if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) { if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) {
...@@ -550,13 +550,27 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { ...@@ -550,13 +550,27 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
if !finded { if !finded {
continue continue
} }
if len(values) > 0 { var returnurl string
return route.pattern + "?" + urlv.Encode() 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 { if route.controllerType.Name() == controllName {
var finded bool var finded bool
if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) { if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) {
...@@ -581,24 +595,10 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { ...@@ -581,24 +595,10 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
if !finded { if !finded {
continue continue
} }
var returnurl string if len(values) > 0 {
var i int return route.pattern + "?" + urlv.Encode()
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
} }
} }
if p.enableAuto { 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