astaxie
|
2629de28f2
|
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)
}
|
2014-05-16 10:18:19 +08:00 |
|
astaxie
|
9d84969bf6
|
fix #153
已经支持了任意定义变量的路由形式,具体的使用请参考:
func TestManyRoute(t *testing.T) {
r, _ := http.NewRequest("GET", "/beego32-12.html", nil)
w := httptest.NewRecorder()
handler := NewControllerRegistor()
handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{})
handler.ServeHTTP(w, r)
id := r.URL.Query().Get(":id")
page := r.URL.Query().Get(":page")
if id != "32" {
t.Errorf("url param set to [%s]; want [%s]", id, "32")
}
if page != "12" {
t.Errorf("url param set to [%s]; want [%s]", page, "12")
}
}
|
2013-09-13 11:22:14 +08:00 |
|