1
0
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:
astaxie
2014-05-16 10:18:15 +08:00
parent ef815bf5fc
commit 55ad951bce
4 changed files with 438 additions and 109 deletions

View File

@ -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)