mirror of
https://github.com/astaxie/beego.git
synced 2025-07-04 10:10:20 +00:00
beego: support more router
//design model beego.Get(router, beego.FilterFunc) beego.Post(router, beego.FilterFunc) beego.Put(router, beego.FilterFunc) beego.Head(router, beego.FilterFunc) beego.Options(router, beego.FilterFunc) beego.Delete(router, beego.FilterFunc) beego.Handler(router, http.Handler) //example beego.Get("/user", func(ctx *context.Context) { ctx.Output.Body([]byte("Get userlist")) }) beego.Post("/user", func(ctx *context.Context) { ctx.Output.Body([]byte("add userlist")) }) beego.Delete("/user/:id", func(ctx *context.Context) { ctx.Output.Body([]byte([]byte(ctx.Input.Param(":id"))) }) import ( "http" "github.com/gorilla/rpc" "github.com/gorilla/rpc/json" ) func init() { s := rpc.NewServer() s.RegisterCodec(json.NewCodec(), "application/json") s.RegisterService(new(HelloService), "") beego.Handler("/rpc", s) }
This commit is contained in:
54
beego.go
54
beego.go
@ -121,6 +121,60 @@ func AutoPrefix(prefix string, c ControllerInterface) *App {
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Get method
|
||||
func Get(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Get(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Post method
|
||||
func Post(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Post(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Delete method
|
||||
func Delete(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Delete(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Put method
|
||||
func Put(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Put(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Head method
|
||||
func Head(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Head(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Options method
|
||||
func Options(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Options(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for Patch method
|
||||
func Patch(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Patch(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for all method
|
||||
func Any(rootpath string, f FilterFunc) *App {
|
||||
BeeApp.Any(rootpath, f)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// register router for own Handler
|
||||
func Handler(rootpath string, h http.Handler) *App {
|
||||
BeeApp.Handler(rootpath, h)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
// ErrorHandler registers http.HandlerFunc to each http err code string.
|
||||
// usage:
|
||||
// beego.ErrorHandler("404",NotFound)
|
||||
|
Reference in New Issue
Block a user