@@ -1889,11 +1889,11 @@ func Test_Bind_RepeatParserWithSameStruct(t *testing.T) {
1889
1889
}
1890
1890
1891
1891
type RequestConfig struct {
1892
- ContentType string
1893
- Body []byte
1894
1892
Headers map [string ]string
1895
1893
Cookies map [string ]string
1894
+ ContentType string
1896
1895
Query string
1896
+ Body []byte
1897
1897
}
1898
1898
1899
1899
func (rc * RequestConfig ) ApplyTo (ctx Ctx ) {
@@ -1919,12 +1919,12 @@ func (rc *RequestConfig) ApplyTo(ctx Ctx) {
1919
1919
func Test_Bind_All (t * testing.T ) {
1920
1920
t .Parallel ()
1921
1921
type User struct {
1922
- ID int `param:"id" query:"id" json:"id" form:"id"`
1923
1922
Avatar * multipart.FileHeader `form:"avatar"`
1924
1923
Name string `query:"name" json:"name" form:"name"`
1925
1924
Email string `json:"email" form:"email"`
1926
- Role string `header:"x-user-role "`
1925
+ Role string `header:"X-User-Role "`
1927
1926
SessionID string `json:"session_id" cookie:"session_id"`
1927
+ ID int `param:"id" query:"id" json:"id" form:"id"`
1928
1928
}
1929
1929
newBind := func (app * App ) * Bind {
1930
1930
return & Bind {
@@ -1937,7 +1937,7 @@ func Test_Bind_All(t *testing.T) {
1937
1937
ContentType : MIMEApplicationJSON ,
1938
1938
Body : []
byte (
`{"name":"john", "email": "[email protected] ", "session_id": "abc1234", "id": 1}` ),
1939
1939
Headers : map [string ]string {
1940
- "x-user-role " : "admin" ,
1940
+ "X-User-Role " : "admin" ,
1941
1941
},
1942
1942
Cookies : map [string ]string {
1943
1943
"session_id" : "abc123" ,
@@ -1947,10 +1947,10 @@ func Test_Bind_All(t *testing.T) {
1947
1947
}
1948
1948
1949
1949
tests := []struct {
1950
- name string
1951
1950
out any
1952
1951
expected * User
1953
1952
config * RequestConfig
1953
+ name string
1954
1954
wantErr bool
1955
1955
}{
1956
1956
{
@@ -2013,6 +2013,7 @@ func Test_Bind_All(t *testing.T) {
2013
2013
2014
2014
for _ , tt := range tests {
2015
2015
t .Run (tt .name , func (t * testing.T ) {
2016
+ t .Parallel ()
2016
2017
bind := newBind (app )
2017
2018
2018
2019
if tt .config != nil {
@@ -2024,7 +2025,7 @@ func Test_Bind_All(t *testing.T) {
2024
2025
assert .Error (t , err )
2025
2026
return
2026
2027
}
2027
- assert .NoError (t , err )
2028
+ require .NoError (t , err )
2028
2029
2029
2030
if tt .expected != nil {
2030
2031
actual , ok := tt .out .(* User )
@@ -2044,9 +2045,9 @@ func Test_Bind_All(t *testing.T) {
2044
2045
func Test_Bind_All_Uri_Precedence (t * testing.T ) {
2045
2046
t .Parallel ()
2046
2047
type User struct {
2047
- ID int `param:"id" json:"id" query:"id" form:"id"`
2048
2048
Name string `json:"name"`
2049
2049
Email string `json:"email"`
2050
+ ID int `param:"id" json:"id" query:"id" form:"id"`
2050
2051
}
2051
2052
2052
2053
app := New ()
@@ -2074,12 +2075,11 @@ func Test_Bind_All_Uri_Precedence(t *testing.T) {
2074
2075
// go test -v -run=^$ -bench=Benchmark_Bind_All -benchmem -count=4
2075
2076
func BenchmarkBind_All (b * testing.B ) {
2076
2077
type User struct {
2077
- ID int `param:"id" query:"id" json:"id" form:"id"`
2078
- Avatar * multipart.FileHeader `form:"avatar"`
2079
- Name string `query:"name" json:"name" form:"name"`
2080
- Email string `json:"email" form:"email"`
2081
- Role string `header:"x-user-role"`
2082
- SessionID string `json:"session_id" cookie:"session_id"`
2078
+ SessionID string `json:"session_id" cookie:"session_id"`
2079
+ Name string `query:"name" json:"name" form:"name"`
2080
+ Email string `json:"email" form:"email"`
2081
+ Role string `header:"X-User-Role"`
2082
+ ID int `param:"id" query:"id" json:"id" form:"id"`
2083
2083
}
2084
2084
2085
2085
app := New ()
@@ -2089,7 +2089,7 @@ func BenchmarkBind_All(b *testing.B) {
2089
2089
ContentType : MIMEApplicationJSON ,
2090
2090
Body : []
byte (
`{"name":"john", "email": "[email protected] ", "session_id": "abc1234", "id": 1}` ),
2091
2091
Headers : map [string ]string {
2092
- "x-user-role " : "admin" ,
2092
+ "X-User-Role " : "admin" ,
2093
2093
},
2094
2094
Cookies : map [string ]string {
2095
2095
"session_id" : "abc123" ,
0 commit comments