示例#1
0
文件: router_test.go 项目: g10f/mix
func TestBasicParams(t *testing.T) {
	m := mix.New()
	m.Get("/pages/:pageId/events/:id", func(rw http.ResponseWriter, r *http.Request) {
		params := mix.Params(r)
		fmt.Fprint(rw, params["pageId"], params["id"])
	})

	res := req(m, "GET", "/pages/123/events/456")
	equals(t, "123456", res.Body.String())
}
示例#2
0
文件: router_test.go 项目: g10f/mix
func TestGroup(t *testing.T) {
	m := mix.New()
	m.Group("/admin", func(r *mix.Router) {
		r.Get("/pages", func(rw http.ResponseWriter, r *http.Request) {
			fmt.Fprint(rw, "pages route")
		})
		r.Get("/events/:id", func(rw http.ResponseWriter, r *http.Request) {
			fmt.Fprint(rw, mix.Params(r)["id"])
		})
	})
	res := req(m, "GET", "/admin/pages")
	equals(t, "pages route", res.Body.String())
	res = req(m, "GET", "/admin/events/123")
	equals(t, "123", res.Body.String())
}