@@ -77,7 +77,16 @@ func (b *Bind) Custom(name string, dest any) error {
77
77
78
78
// Header binds the request header strings into the struct, map[string]string and map[string][]string.
79
79
func (b * Bind ) Header (out any ) error {
80
- if err := b .returnErr (binder .HeaderBinder .Bind (b .ctx .Request (), out )); err != nil {
80
+ bind := binder.GetFromThePool [* binder.HeaderBinding ](& binder .HeaderBinderPool )
81
+ bind .EnableSplitting = b .ctx .App ().config .EnableSplittingOnParsers
82
+
83
+ // Reset & put binder
84
+ defer func () {
85
+ bind .Reset ()
86
+ binder .PutToThePool (& binder .HeaderBinderPool , bind )
87
+ }()
88
+
89
+ if err := b .returnErr (bind .Bind (b .ctx .Request (), out )); err != nil {
81
90
return err
82
91
}
83
92
@@ -86,7 +95,16 @@ func (b *Bind) Header(out any) error {
86
95
87
96
// RespHeader binds the response header strings into the struct, map[string]string and map[string][]string.
88
97
func (b * Bind ) RespHeader (out any ) error {
89
- if err := b .returnErr (binder .RespHeaderBinder .Bind (b .ctx .Response (), out )); err != nil {
98
+ bind := binder.GetFromThePool [* binder.RespHeaderBinding ](& binder .RespHeaderBinderPool )
99
+ bind .EnableSplitting = b .ctx .App ().config .EnableSplittingOnParsers
100
+
101
+ // Reset & put binder
102
+ defer func () {
103
+ bind .Reset ()
104
+ binder .PutToThePool (& binder .RespHeaderBinderPool , bind )
105
+ }()
106
+
107
+ if err := b .returnErr (bind .Bind (b .ctx .Response (), out )); err != nil {
90
108
return err
91
109
}
92
110
@@ -96,7 +114,16 @@ func (b *Bind) RespHeader(out any) error {
96
114
// Cookie binds the request cookie strings into the struct, map[string]string and map[string][]string.
97
115
// NOTE: If your cookie is like key=val1,val2; they'll be binded as an slice if your map is map[string][]string. Else, it'll use last element of cookie.
98
116
func (b * Bind ) Cookie (out any ) error {
99
- if err := b .returnErr (binder .CookieBinder .Bind (b .ctx .RequestCtx (), out )); err != nil {
117
+ bind := binder.GetFromThePool [* binder.CookieBinding ](& binder .CookieBinderPool )
118
+ bind .EnableSplitting = b .ctx .App ().config .EnableSplittingOnParsers
119
+
120
+ // Reset & put binder
121
+ defer func () {
122
+ bind .Reset ()
123
+ binder .PutToThePool (& binder .CookieBinderPool , bind )
124
+ }()
125
+
126
+ if err := b .returnErr (bind .Bind (& b .ctx .RequestCtx ().Request , out )); err != nil {
100
127
return err
101
128
}
102
129
@@ -105,7 +132,16 @@ func (b *Bind) Cookie(out any) error {
105
132
106
133
// Query binds the query string into the struct, map[string]string and map[string][]string.
107
134
func (b * Bind ) Query (out any ) error {
108
- if err := b .returnErr (binder .QueryBinder .Bind (b .ctx .RequestCtx (), out )); err != nil {
135
+ bind := binder.GetFromThePool [* binder.QueryBinding ](& binder .QueryBinderPool )
136
+ bind .EnableSplitting = b .ctx .App ().config .EnableSplittingOnParsers
137
+
138
+ // Reset & put binder
139
+ defer func () {
140
+ bind .Reset ()
141
+ binder .PutToThePool (& binder .QueryBinderPool , bind )
142
+ }()
143
+
144
+ if err := b .returnErr (bind .Bind (& b .ctx .RequestCtx ().Request , out )); err != nil {
109
145
return err
110
146
}
111
147
@@ -114,7 +150,16 @@ func (b *Bind) Query(out any) error {
114
150
115
151
// JSON binds the body string into the struct.
116
152
func (b * Bind ) JSON (out any ) error {
117
- if err := b .returnErr (binder .JSONBinder .Bind (b .ctx .Body (), b .ctx .App ().Config ().JSONDecoder , out )); err != nil {
153
+ bind := binder.GetFromThePool [* binder.JSONBinding ](& binder .JSONBinderPool )
154
+ bind .JSONDecoder = b .ctx .App ().Config ().JSONDecoder
155
+
156
+ // Reset & put binder
157
+ defer func () {
158
+ bind .Reset ()
159
+ binder .PutToThePool (& binder .JSONBinderPool , bind )
160
+ }()
161
+
162
+ if err := b .returnErr (bind .Bind (b .ctx .Body (), out )); err != nil {
118
163
return err
119
164
}
120
165
@@ -123,24 +168,54 @@ func (b *Bind) JSON(out any) error {
123
168
124
169
// CBOR binds the body string into the struct.
125
170
func (b * Bind ) CBOR (out any ) error {
126
- if err := b .returnErr (binder .CBORBinder .Bind (b .ctx .Body (), b .ctx .App ().Config ().CBORDecoder , out )); err != nil {
171
+ bind := binder.GetFromThePool [* binder.CBORBinding ](& binder .CBORBinderPool )
172
+ bind .CBORDecoder = b .ctx .App ().Config ().CBORDecoder
173
+
174
+ // Reset & put binder
175
+ defer func () {
176
+ bind .Reset ()
177
+ binder .PutToThePool (& binder .CBORBinderPool , bind )
178
+ }()
179
+
180
+ if err := b .returnErr (bind .Bind (b .ctx .Body (), out )); err != nil {
127
181
return err
128
182
}
129
183
return b .validateStruct (out )
130
184
}
131
185
132
186
// XML binds the body string into the struct.
133
187
func (b * Bind ) XML (out any ) error {
134
- if err := b .returnErr (binder .XMLBinder .Bind (b .ctx .Body (), out )); err != nil {
188
+ bind := binder.GetFromThePool [* binder.XMLBinding ](& binder .XMLBinderPool )
189
+ bind .XMLDecoder = b .ctx .App ().config .XMLDecoder
190
+
191
+ // Reset & put binder
192
+ defer func () {
193
+ bind .Reset ()
194
+ binder .PutToThePool (& binder .XMLBinderPool , bind )
195
+ }()
196
+
197
+ if err := b .returnErr (bind .Bind (b .ctx .Body (), out )); err != nil {
135
198
return err
136
199
}
137
200
138
201
return b .validateStruct (out )
139
202
}
140
203
141
204
// Form binds the form into the struct, map[string]string and map[string][]string.
205
+ // If Content-Type is "application/x-www-form-urlencoded" or "multipart/form-data", it will bind the form values.
206
+ //
207
+ // Binding multipart files is not supported yet.
142
208
func (b * Bind ) Form (out any ) error {
143
- if err := b .returnErr (binder .FormBinder .Bind (b .ctx .RequestCtx (), out )); err != nil {
209
+ bind := binder.GetFromThePool [* binder.FormBinding ](& binder .FormBinderPool )
210
+ bind .EnableSplitting = b .ctx .App ().config .EnableSplittingOnParsers
211
+
212
+ // Reset & put binder
213
+ defer func () {
214
+ bind .Reset ()
215
+ binder .PutToThePool (& binder .FormBinderPool , bind )
216
+ }()
217
+
218
+ if err := b .returnErr (bind .Bind (& b .ctx .RequestCtx ().Request , out )); err != nil {
144
219
return err
145
220
}
146
221
@@ -149,16 +224,14 @@ func (b *Bind) Form(out any) error {
149
224
150
225
// URI binds the route parameters into the struct, map[string]string and map[string][]string.
151
226
func (b * Bind ) URI (out any ) error {
152
- if err := b .returnErr (binder .URIBinder .Bind (b .ctx .Route ().Params , b .ctx .Params , out )); err != nil {
153
- return err
154
- }
227
+ bind := binder.GetFromThePool [* binder.URIBinding ](& binder .URIBinderPool )
155
228
156
- return b .validateStruct (out )
157
- }
229
+ // Reset & put binder
230
+ defer func () {
231
+ binder .PutToThePool (& binder .URIBinderPool , bind )
232
+ }()
158
233
159
- // MultipartForm binds the multipart form into the struct, map[string]string and map[string][]string.
160
- func (b * Bind ) MultipartForm (out any ) error {
161
- if err := b .returnErr (binder .FormBinder .BindMultipart (b .ctx .RequestCtx (), out )); err != nil {
234
+ if err := b .returnErr (bind .Bind (b .ctx .Route ().Params , b .ctx .Params , out )); err != nil {
162
235
return err
163
236
}
164
237
@@ -193,10 +266,8 @@ func (b *Bind) Body(out any) error {
193
266
return b .XML (out )
194
267
case MIMEApplicationCBOR :
195
268
return b .CBOR (out )
196
- case MIMEApplicationForm :
269
+ case MIMEApplicationForm , MIMEMultipartForm :
197
270
return b .Form (out )
198
- case MIMEMultipartForm :
199
- return b .MultipartForm (out )
200
271
}
201
272
202
273
// No suitable content type found
0 commit comments