|
|
@ -47,7 +47,7 @@ func TestPatRouterHandleErrors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.method, func(t *testing.T) {
|
|
|
|
t.Run(test.method, func(t *testing.T) {
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err := router.Handle(test.method, test.path, nil)
|
|
|
|
err := router.Handle(test.method, test.path, nil)
|
|
|
|
assert.Error(t, ErrInvalidMethod, err)
|
|
|
|
assert.Error(t, ErrInvalidMethod, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -56,7 +56,7 @@ func TestPatRouterHandleErrors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestPatRouterNotFound(t *testing.T) {
|
|
|
|
func TestPatRouterNotFound(t *testing.T) {
|
|
|
|
var notFound bool
|
|
|
|
var notFound bool
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
router.SetNotFoundHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
router.SetNotFoundHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
notFound = true
|
|
|
|
notFound = true
|
|
|
|
}))
|
|
|
|
}))
|
|
|
@ -87,7 +87,7 @@ func TestPatRouter(t *testing.T) {
|
|
|
|
for _, test := range tests {
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.method+":"+test.path, func(t *testing.T) {
|
|
|
|
t.Run(test.method+":"+test.path, func(t *testing.T) {
|
|
|
|
routed := false
|
|
|
|
routed := false
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
routed = true
|
|
|
|
routed = true
|
|
|
|
assert.Equal(t, 1, len(context.Vars(r)))
|
|
|
|
assert.Equal(t, 1, len(context.Vars(r)))
|
|
|
@ -125,7 +125,7 @@ func TestParseSlice(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
|
|
|
|
|
|
rt := NewPatRouter()
|
|
|
|
rt := NewRouter()
|
|
|
|
err = rt.Handle(http.MethodPost, "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err = rt.Handle(http.MethodPost, "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
|
Names []string `form:"names"`
|
|
|
|
Names []string `form:"names"`
|
|
|
@ -149,7 +149,7 @@ func TestParseJsonPost(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(
|
|
|
|
w http.ResponseWriter, r *http.Request) {
|
|
|
|
w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -181,7 +181,7 @@ func TestParseJsonPostWithIntSlice(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(
|
|
|
|
w http.ResponseWriter, r *http.Request) {
|
|
|
|
w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -209,7 +209,7 @@ func TestParseJsonPostError(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -237,7 +237,7 @@ func TestParseJsonPostInvalidRequest(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -259,7 +259,7 @@ func TestParseJsonPostRequired(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -282,7 +282,7 @@ func TestParsePath(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -307,7 +307,7 @@ func TestParsePathRequired(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -328,7 +328,7 @@ func TestParseQuery(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -353,7 +353,7 @@ func TestParseQueryRequired(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodPost, "http://hello.com/kevin/2017?nickname=whatever", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodPost, "http://hello.com/kevin/2017?nickname=whatever", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
|
Nickname string `form:"nickname"`
|
|
|
|
Nickname string `form:"nickname"`
|
|
|
@ -373,7 +373,7 @@ func TestParseOptional(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -414,7 +414,7 @@ func TestParseNestedInRequestEmpty(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -453,7 +453,7 @@ func TestParsePtrInRequest(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -484,7 +484,7 @@ func TestParsePtrInRequestEmpty(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/kevin", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/kevin", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -501,7 +501,7 @@ func TestParseQueryOptional(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -526,7 +526,7 @@ func TestParse(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -564,7 +564,7 @@ func TestParseWrappedRequest(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -596,7 +596,7 @@ func TestParseWrappedGetRequestWithJsonHeader(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -629,7 +629,7 @@ func TestParseWrappedHeadRequestWithJsonHeader(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodHead, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodHead, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -661,7 +661,7 @@ func TestParseWrappedRequestPtr(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var v WrappedRequest
|
|
|
|
var v WrappedRequest
|
|
|
@ -684,7 +684,7 @@ func TestParseWithAll(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
|
Name string `path:"name"`
|
|
|
|
Name string `path:"name"`
|
|
|
@ -715,7 +715,7 @@ func TestParseWithAllUtf8(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
|
|
|
|
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -746,7 +746,7 @@ func TestParseWithMissingForm(t *testing.T) {
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -773,7 +773,7 @@ func TestParseWithMissingAllForms(t *testing.T) {
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -799,7 +799,7 @@ func TestParseWithMissingJson(t *testing.T) {
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai"}`))
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai"}`))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -825,7 +825,7 @@ func TestParseWithMissingAllJsons(t *testing.T) {
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
|
|
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -852,7 +852,7 @@ func TestParseWithMissingPath(t *testing.T) {
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -879,7 +879,7 @@ func TestParseWithMissingAllPaths(t *testing.T) {
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -906,7 +906,7 @@ func TestParseGetWithContentLengthHeader(t *testing.T) {
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
|
|
|
|
r.Header.Set(contentLength, "1024")
|
|
|
|
r.Header.Set(contentLength, "1024")
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -933,7 +933,7 @@ func TestParseJsonPostWithTypeMismatch(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
|
|
|
|
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -959,7 +959,7 @@ func TestParseJsonPostWithInt2String(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
|
|
|
|
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := struct {
|
|
|
|
v := struct {
|
|
|
@ -980,7 +980,7 @@ func TestParseJsonPostWithInt2String(t *testing.T) {
|
|
|
|
func BenchmarkPatRouter(b *testing.B) {
|
|
|
|
func BenchmarkPatRouter(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
|
|
|
|
router := NewPatRouter()
|
|
|
|
router := NewRouter()
|
|
|
|
router.Handle(http.MethodGet, "/api/:user/:name", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
router.Handle(http.MethodGet, "/api/:user/:name", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
w := &mockedResponseWriter{}
|
|
|
|
w := &mockedResponseWriter{}
|
|
|
|