fix: type matching supports string to int (#2038)

* fix: type matching supports string to int

* feat: type matching supports string to int

Co-authored-by: 程家福 <chengjiafu@uniontech.com>
This commit is contained in:
家福
2022-07-01 23:21:31 +08:00
committed by GitHub
parent 6a4885ba64
commit f3b8fef34f
5 changed files with 126 additions and 3 deletions

View File

@@ -38,3 +38,14 @@ func TestParseHeadersMulti(t *testing.T) {
assert.Equal(t, 1, val.Baz)
assert.True(t, val.Qux)
}
func TestParseHeadersArrayInt(t *testing.T) {
var val struct {
Foo []int `header:"foo"`
}
r := httptest.NewRequest(http.MethodGet, "/any", nil)
r.Header.Set("foo", "1")
r.Header.Add("foo", "2")
assert.Nil(t, ParseHeaders(r.Header, &val))
assert.Equal(t, []int{1, 2}, val.Foo)
}