@@ -77,7 +77,16 @@ func (b *Bind) Custom(name string, dest any) error {
7777
7878// Header binds the request header strings into the struct, map[string]string and map[string][]string.
7979func (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 {
8190 return err
8291 }
8392
@@ -86,7 +95,16 @@ func (b *Bind) Header(out any) error {
8695
8796// RespHeader binds the response header strings into the struct, map[string]string and map[string][]string.
8897func (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 {
90108 return err
91109 }
92110
@@ -96,7 +114,16 @@ func (b *Bind) RespHeader(out any) error {
96114// Cookie binds the request cookie strings into the struct, map[string]string and map[string][]string.
97115// 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.
98116func (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 {
100127 return err
101128 }
102129
@@ -105,7 +132,16 @@ func (b *Bind) Cookie(out any) error {
105132
106133// Query binds the query string into the struct, map[string]string and map[string][]string.
107134func (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 {
109145 return err
110146 }
111147
@@ -114,7 +150,16 @@ func (b *Bind) Query(out any) error {
114150
115151// JSON binds the body string into the struct.
116152func (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 {
118163 return err
119164 }
120165
@@ -123,24 +168,54 @@ func (b *Bind) JSON(out any) error {
123168
124169// CBOR binds the body string into the struct.
125170func (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 {
127181 return err
128182 }
129183 return b .validateStruct (out )
130184}
131185
132186// XML binds the body string into the struct.
133187func (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 {
135198 return err
136199 }
137200
138201 return b .validateStruct (out )
139202}
140203
141204// 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.
142208func (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 {
144219 return err
145220 }
146221
@@ -149,16 +224,14 @@ func (b *Bind) Form(out any) error {
149224
150225// URI binds the route parameters into the struct, map[string]string and map[string][]string.
151226func (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 )
155228
156- return b .validateStruct (out )
157- }
229+ // Reset & put binder
230+ defer func () {
231+ binder .PutToThePool (& binder .URIBinderPool , bind )
232+ }()
158233
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 {
162235 return err
163236 }
164237
@@ -193,10 +266,8 @@ func (b *Bind) Body(out any) error {
193266 return b .XML (out )
194267 case MIMEApplicationCBOR :
195268 return b .CBOR (out )
196- case MIMEApplicationForm :
269+ case MIMEApplicationForm , MIMEMultipartForm :
197270 return b .Form (out )
198- case MIMEMultipartForm :
199- return b .MultipartForm (out )
200271 }
201272
202273 // No suitable content type found
0 commit comments