diff --git a/beego.go b/beego.go index ba28855d..8a626eae 100644 --- a/beego.go +++ b/beego.go @@ -42,73 +42,6 @@ const VERSION = "1.4.2" type hookfunc func() error //hook function to run var hooks []hookfunc //hook function slice to store the hookfunc -type groupRouter struct { - pattern string - controller ControllerInterface - mappingMethods string -} - -// RouterGroups which will store routers -type GroupRouters []groupRouter - -// Get a new GroupRouters -func NewGroupRouters() GroupRouters { - return make(GroupRouters, 0) -} - -// Add Router in the GroupRouters -// it is for plugin or module to register router -func (gr *GroupRouters) AddRouter(pattern string, c ControllerInterface, mappingMethod ...string) { - var newRG groupRouter - if len(mappingMethod) > 0 { - newRG = groupRouter{ - pattern, - c, - mappingMethod[0], - } - } else { - newRG = groupRouter{ - pattern, - c, - "", - } - } - *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: -// GR:=NewGroupRouters() -// GR.AddRouter("/login",&UserController,"get:Login") -// GR.AddRouter("/logout",&UserController,"get:Logout") -// GR.AddRouter("/register",&UserController,"get:Reg") -// the follow code is write in app: -// import "github.com/beego/modules/auth" -// AddRouterGroup("/admin", auth.GR) -func AddGroupRouter(prefix string, groups GroupRouters) *App { - for _, v := range groups { - if v.pattern == "" { - BeeApp.Handlers.AddAutoPrefix(prefix, v.controller) - } else if v.mappingMethods != "" { - BeeApp.Handlers.Add(prefix+v.pattern, v.controller, v.mappingMethods) - } else { - BeeApp.Handlers.Add(prefix+v.pattern, v.controller) - } - - } - return BeeApp -} - // Router adds a patterned controller handler to BeeApp. // it's an alias method of App.Router. // usage: