fix issue #4176: refactor Router with option pattern

This commit is contained in:
AllenX2018
2020-11-20 10:43:30 +08:00
parent 05d8e293f7
commit 463ec4b085
10 changed files with 96 additions and 74 deletions

View File

@@ -74,7 +74,7 @@ func oldMiddlewareToNew(mws []MiddleWare) []web.MiddleWare {
// beego.Router("/api/update",&RestController{},"put:UpdateFood")
// beego.Router("/api/delete",&RestController{},"delete:DeleteFood")
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
return (*App)(web.Router(rootpath, c, mappingMethods...))
return (*App)(web.Router(rootpath, c, web.WithMethods(c, mappingMethods...)))
}
// UnregisterFixedRoute unregisters the route with the specified fixedRoute. It is particularly useful

View File

@@ -272,7 +272,7 @@ func NSInclude(cList ...ControllerInterface) LinkNamespace {
// NSRouter call Namespace Router
func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) LinkNamespace {
return func(namespace *Namespace) {
web.Router(rootpath, c, mappingMethods...)
web.Router(rootpath, c, web.WithMethods(c, mappingMethods...))
}
}

View File

@@ -87,7 +87,7 @@ func NewControllerRegister() *ControllerRegister {
// Add("/api",&RestController{},"get,post:ApiFunc"
// Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
func (p *ControllerRegister) Add(pattern string, c ControllerInterface, mappingMethods ...string) {
(*web.ControllerRegister)(p).Add(pattern, c, mappingMethods...)
(*web.ControllerRegister)(p).Add(pattern, c, web.WithMethods(c, mappingMethods...))
}
// Include only when the Runmode is dev will generate router file in the router/auto.go from the controller