mirror of
https://github.com/astaxie/beego.git
synced 2024-12-23 10:10:49 +00:00
beego: improve the admin router print
This commit is contained in:
parent
d2eece9a39
commit
f6c7a6bd32
28
admin.go
28
admin.go
@ -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 {
|
||||
|
62
router.go
62
router.go
@ -525,37 +525,6 @@ 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 {
|
||||
if route.controllerType.Name() == controllName {
|
||||
var finded bool
|
||||
if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) {
|
||||
if route.hasMethod {
|
||||
if m, ok := route.methods[strings.ToLower(methodName)]; ok && m != methodName {
|
||||
finded = false
|
||||
} else if m, ok = route.methods["*"]; ok && m != methodName {
|
||||
finded = false
|
||||
} else {
|
||||
finded = true
|
||||
}
|
||||
} else {
|
||||
finded = true
|
||||
}
|
||||
} else if route.hasMethod {
|
||||
for _, md := range route.methods {
|
||||
if md == methodName {
|
||||
finded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !finded {
|
||||
continue
|
||||
}
|
||||
if len(values) > 0 {
|
||||
return route.pattern + "?" + urlv.Encode()
|
||||
}
|
||||
return route.pattern
|
||||
}
|
||||
}
|
||||
for _, route := range p.routers {
|
||||
if route.controllerType.Name() == controllName {
|
||||
var finded bool
|
||||
@ -601,6 +570,37 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, route := range p.fixrouters {
|
||||
if route.controllerType.Name() == controllName {
|
||||
var finded bool
|
||||
if utils.InSlice(strings.ToLower(methodName), HTTPMETHOD) {
|
||||
if route.hasMethod {
|
||||
if m, ok := route.methods[strings.ToLower(methodName)]; ok && m != methodName {
|
||||
finded = false
|
||||
} else if m, ok = route.methods["*"]; ok && m != methodName {
|
||||
finded = false
|
||||
} else {
|
||||
finded = true
|
||||
}
|
||||
} else {
|
||||
finded = true
|
||||
}
|
||||
} else if route.hasMethod {
|
||||
for _, md := range route.methods {
|
||||
if md == methodName {
|
||||
finded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !finded {
|
||||
continue
|
||||
}
|
||||
if len(values) > 0 {
|
||||
return route.pattern + "?" + urlv.Encode()
|
||||
}
|
||||
return route.pattern
|
||||
}
|
||||
}
|
||||
if p.enableAuto {
|
||||
for cName, methodList := range p.autoRouter {
|
||||
if strings.ToLower(strings.TrimSuffix(paths[len(paths)-2], "Controller")) == cName {
|
||||
|
Loading…
Reference in New Issue
Block a user