mirror of
https://github.com/astaxie/beego.git
synced 2025-07-04 09:50:18 +00:00
add AutoRouterWithPrefix
This commit is contained in:
20
beego.go
20
beego.go
@ -50,6 +50,15 @@ func (gr GroupRouters) AddRouter(pattern string, c ControllerInterface, mappingM
|
||||
gr = append(gr, newRG)
|
||||
}
|
||||
|
||||
func (gr GroupRouters) AddAuto(c ControllerInterface) {
|
||||
newRG := groupRouter{
|
||||
"",
|
||||
c,
|
||||
"",
|
||||
}
|
||||
gr = append(gr, newRG)
|
||||
}
|
||||
|
||||
// AddGroupRouter with the prefix
|
||||
// it will register the router in BeeApp
|
||||
// the follow code is write in modules:
|
||||
@ -62,7 +71,9 @@ func (gr GroupRouters) AddRouter(pattern string, c ControllerInterface, mappingM
|
||||
// AddRouterGroup("/admin", auth.GR)
|
||||
func AddGroupRouter(prefix string, groups GroupRouters) *App {
|
||||
for _, v := range groups {
|
||||
if v.mappingMethods != "" {
|
||||
if v.pattern == "" {
|
||||
BeeApp.AutoRouterWithPrefix(prefix, v.controller)
|
||||
} else if v.mappingMethods != "" {
|
||||
BeeApp.Router(prefix+v.pattern, v.controller, v.mappingMethods)
|
||||
} else {
|
||||
BeeApp.Router(prefix+v.pattern, v.controller)
|
||||
@ -95,6 +106,13 @@ func AutoRouter(c ControllerInterface) *App {
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// AutoPrefix adds controller handler to BeeApp with prefix.
|
||||
// it's same to App.AutoRouterWithPrefix.
|
||||
func AutoPrefix(prefix string, c ControllerInterface) *App {
|
||||
BeeApp.AutoRouterWithPrefix(prefix, c)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// ErrorHandler registers http.HandlerFunc to each http err code string.
|
||||
// usage:
|
||||
// beego.ErrorHandler("404",NotFound)
|
||||
|
Reference in New Issue
Block a user