add all router methods and functions

This commit is contained in:
Jason li 2021-01-07 19:29:22 +08:00
parent 07d0dccd89
commit cbbc296efb
3 changed files with 343 additions and 1 deletions

View File

@ -187,6 +187,54 @@ func (n *Namespace) Include(cList ...ControllerInterface) *Namespace {
return n return n
} }
// RouterGet same as beego.RouterGet
func (n *Namespace) RouterGet(rootpath string, f interface{}) *Namespace {
n.handlers.RouterGet(rootpath, f)
return n
}
// RouterPost same as beego.RouterPost
func (n *Namespace) RouterPost(rootpath string, f interface{}) *Namespace {
n.handlers.RouterPost(rootpath, f)
return n
}
// RouterDelete same as beego.RouterDelete
func (n *Namespace) RouterDelete(rootpath string, f interface{}) *Namespace {
n.handlers.RouterDelete(rootpath, f)
return n
}
// RouterPut same as beego.RouterPut
func (n *Namespace) RouterPut(rootpath string, f interface{}) *Namespace {
n.handlers.RouterPut(rootpath, f)
return n
}
// RouterHead same as beego.RouterHead
func (n *Namespace) RouterHead(rootpath string, f interface{}) *Namespace {
n.handlers.RouterHead(rootpath, f)
return n
}
// RouterOptions same as beego.RouterOptions
func (n *Namespace) RouterOptions(rootpath string, f interface{}) *Namespace {
n.handlers.RouterOptions(rootpath, f)
return n
}
// RouterPatch same as beego.RouterPatch
func (n *Namespace) RouterPatch(rootpath string, f interface{}) *Namespace {
n.handlers.RouterPatch(rootpath, f)
return n
}
// Any same as beego.RouterAny
func (n *Namespace) RouterAny(rootpath string, f interface{}) *Namespace {
n.handlers.RouterAny(rootpath, f)
return n
}
// Namespace add nest Namespace // Namespace add nest Namespace
// usage: // usage:
// ns := beego.NewNamespace(“/v1”). // ns := beego.NewNamespace(“/v1”).
@ -366,6 +414,62 @@ func NSPatch(rootpath string, f FilterFunc) LinkNamespace {
} }
} }
// NSRouterGet call Namespace RouterGet
func NSRouterGet(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterGet(rootpath, f)
}
}
// NSPost call Namespace RouterPost
func NSRouterPost(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterPost(rootpath, f)
}
}
// NSRouterHead call Namespace RouterHead
func NSRouterHead(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterHead(rootpath, f)
}
}
// NSRouterPut call Namespace RouterPut
func NSRouterPut(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterPut(rootpath, f)
}
}
// NSRouterDelete call Namespace RouterDelete
func NSRouterDelete(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterDelete(rootpath, f)
}
}
// NSRouterAny call Namespace RouterAny
func NSRouterAny(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterAny(rootpath, f)
}
}
// NSRouterOptions call Namespace RouterOptions
func NSRouterOptions(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterOptions(rootpath, f)
}
}
// NSRouterPatch call Namespace RouterPatch
func NSRouterPatch(rootpath string, f interface{}) LinkNamespace {
return func(ns *Namespace) {
ns.RouterPatch(rootpath, f)
}
}
// NSAutoRouter call Namespace AutoRouter // NSAutoRouter call Namespace AutoRouter
func NSAutoRouter(c ControllerInterface) LinkNamespace { func NSAutoRouter(c ControllerInterface) LinkNamespace {
return func(ns *Namespace) { return func(ns *Namespace) {

View File

@ -333,7 +333,7 @@ func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
p.pool.Put(ctx) p.pool.Put(ctx)
} }
// RouterGet add post method // RouterGet add get method
// usage: // usage:
// type MyController struct { // type MyController struct {
// web.Controller // web.Controller
@ -347,6 +347,104 @@ func (p *ControllerRegister) RouterGet(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodGet, pattern, f) p.AddRouterMethod(http.MethodGet, pattern, f)
} }
// RouterPost add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterPost("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterPost(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodPost, pattern, f)
}
// RouterHead add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterHead("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterHead(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodHead, pattern, f)
}
// RouterPut add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterPut("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterPut(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodPut, pattern, f)
}
// RouterPatch add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterPatch("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterPatch(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodPatch, pattern, f)
}
// RouterDelete add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterDelete("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterDelete(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodDelete, pattern, f)
}
// RouterOptions add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterOptions("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterOptions(pattern string, f interface{}) {
p.AddRouterMethod(http.MethodOptions, pattern, f)
}
// RouterAny add post method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterAny("/api/:id", MyController.Ping)
func (p *ControllerRegister) RouterAny(pattern string, f interface{}) {
p.AddRouterMethod("*", pattern, f)
}
// AddRouterMethod add http method router // AddRouterMethod add http method router
// usage: // usage:
// type MyController struct { // type MyController struct {

View File

@ -481,6 +481,146 @@ func (app *HttpServer) RouterGet(rootpath string, f interface{}) *HttpServer {
return app return app
} }
// RouterPost see HttpServer.RouterGet
func RouterPost(rootpath string, f interface{}) {
BeeApp.RouterPost(rootpath, f)
}
// RouterPost used to register router for RouterPost method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterPost("/api/:id", MyController.Ping)
func (app *HttpServer) RouterPost(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterPost(rootpath, f)
return app
}
// RouterHead see HttpServer.RouterHead
func RouterHead(rootpath string, f interface{}) {
BeeApp.RouterPost(rootpath, f)
}
// RouterHead used to register router for RouterHead method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterHead("/api/:id", MyController.Ping)
func (app *HttpServer) RouterHead(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterHead(rootpath, f)
return app
}
// RouterPut see HttpServer.RouterPut
func RouterPut(rootpath string, f interface{}) {
BeeApp.RouterPost(rootpath, f)
}
// RouterPut used to register router for RouterPut method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterPut("/api/:id", MyController.Ping)
func (app *HttpServer) RouterPut(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterPut(rootpath, f)
return app
}
// RouterPatch see HttpServer.RouterPatch
func RouterPatch(rootpath string, f interface{}) {
BeeApp.RouterPatch(rootpath, f)
}
// RouterPatch used to register router for RouterPatch method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterPatch("/api/:id", MyController.Ping)
func (app *HttpServer) RouterPatch(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterPatch(rootpath, f)
return app
}
// RouterDelete see HttpServer.RouterDelete
func RouterDelete(rootpath string, f interface{}) {
BeeApp.RouterDelete(rootpath, f)
}
// RouterDelete used to register router for RouterDelete method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterDelete("/api/:id", MyController.Ping)
func (app *HttpServer) RouterDelete(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterDelete(rootpath, f)
return app
}
// RouterOptions see HttpServer.RouterOptions
func RouterOptions(rootpath string, f interface{}) {
BeeApp.RouterOptions(rootpath, f)
}
// RouterOptions used to register router for RouterOptions method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterOptions("/api/:id", MyController.Ping)
func (app *HttpServer) RouterOptions(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterOptions(rootpath, f)
return app
}
// RouterAny see HttpServer.RouterAny
func RouterAny(rootpath string, f interface{}) {
BeeApp.RouterOptions(rootpath, f)
}
// RouterAny used to register router for RouterAny method
// usage:
// type MyController struct {
// web.Controller
// }
// func (m MyController) Ping() {
// m.Ctx.Output.Body([]byte("hello world"))
// }
//
// RouterAny("/api/:id", MyController.Ping)
func (app *HttpServer) RouterAny(rootpath string, f interface{}) *HttpServer {
app.Handlers.RouterAny(rootpath, f)
return app
}
// Get see HttpServer.Get // Get see HttpServer.Get
func Get(rootpath string, f FilterFunc) *HttpServer { func Get(rootpath string, f FilterFunc) *HttpServer {
return BeeApp.Get(rootpath, f) return BeeApp.Get(rootpath, f)