feat(context): add BindQuery func (#1029)

* feat(context): add BindQuery func, only parse/bind the query string params.

* docs(readme): add BindQuery section.

* docs(readme): fix import.

* docs(readme): separate import
This commit is contained in:
Eason Lin
2017-07-19 15:50:05 +08:00
committed by Javier Provecho Fernandez
parent 74221b8a35
commit c19aa0598b
6 changed files with 109 additions and 1 deletions

View File

@ -1186,6 +1186,22 @@ func TestContextBindWithJSON(t *testing.T) {
assert.Equal(t, w.Body.Len(), 0)
}
func TestContextBindWithQuery(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
c.Request, _ = http.NewRequest("POST", "/?foo=bar&bar=foo", bytes.NewBufferString("foo=unused"))
var obj struct {
Foo string `form:"foo"`
Bar string `form:"bar"`
}
assert.NoError(t, c.BindQuery(&obj))
assert.Equal(t, "foo", obj.Bar)
assert.Equal(t, "bar", obj.Foo)
assert.Equal(t, 0, w.Body.Len())
}
func TestContextBadAutoBind(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)