Exemple #1
0
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())
}
Exemple #2
0
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())
}