Skip to content

Commit

Permalink
add reset methods
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Dec 23, 2024
1 parent 6dea77f commit e2e93a4
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 19 deletions.
29 changes: 10 additions & 19 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ func (b *Bind) Header(out any) error {

// Reset & put binder
defer func() {
bind.EnableSplitting = false
binder.PutToThePool(&binder.HeaderBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(b.ctx.Request(), out)); err != nil {
Expand All @@ -100,8 +99,7 @@ func (b *Bind) RespHeader(out any) error {

// Reset & put binder
defer func() {
bind.EnableSplitting = false
binder.PutToThePool(&binder.RespHeaderBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(b.ctx.Response(), out)); err != nil {
Expand All @@ -119,8 +117,7 @@ func (b *Bind) Cookie(out any) error {

// Reset & put binder
defer func() {
bind.EnableSplitting = false
binder.PutToThePool(&binder.CookieBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(&b.ctx.RequestCtx().Request, out)); err != nil {
Expand All @@ -137,8 +134,7 @@ func (b *Bind) Query(out any) error {

// Reset & put binder
defer func() {
bind.EnableSplitting = false
binder.PutToThePool(&binder.QueryBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(&b.ctx.RequestCtx().Request, out)); err != nil {
Expand All @@ -155,8 +151,7 @@ func (b *Bind) JSON(out any) error {

// Reset & put binder
defer func() {
bind.JSONDecoder = nil
binder.PutToThePool(&binder.JSONBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(b.ctx.Body(), out)); err != nil {
Expand All @@ -173,8 +168,7 @@ func (b *Bind) CBOR(out any) error {

// Reset & put binder
defer func() {
bind.CBORDecoder = nil
binder.PutToThePool(&binder.CBORBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(b.ctx.Body(), out)); err != nil {
Expand All @@ -190,8 +184,7 @@ func (b *Bind) XML(out any) error {

// Reset & put binder
defer func() {
bind.XMLDecoder = nil
binder.PutToThePool(&binder.XMLBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(b.ctx.Body(), out)); err != nil {
Expand All @@ -208,8 +201,7 @@ func (b *Bind) Form(out any) error {

// Reset & put binder
defer func() {
bind.EnableSplitting = false
binder.PutToThePool(&binder.FormBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.Bind(&b.ctx.RequestCtx().Request, out)); err != nil {
Expand All @@ -225,7 +217,7 @@ func (b *Bind) URI(out any) error {

// Reset & put binder
defer func() {
binder.PutToThePool(&binder.URIBinderPool, bind)
bind.Reset()
}()

Check warning on line 221 in bind.go

View check run for this annotation

Codecov / codecov/patch

bind.go#L216-L221

Added lines #L216 - L221 were not covered by tests

if err := b.returnErr(bind.Bind(b.ctx.Route().Params, b.ctx.Params, out)); err != nil {

Check warning on line 223 in bind.go

View check run for this annotation

Codecov / codecov/patch

bind.go#L223

Added line #L223 was not covered by tests
Expand All @@ -242,8 +234,7 @@ func (b *Bind) MultipartForm(out any) error {

// Reset & put binder
defer func() {
bind.EnableSplitting = false
binder.PutToThePool(&binder.FormBinderPool, bind)
bind.Reset()
}()

if err := b.returnErr(bind.BindMultipart(&b.ctx.RequestCtx().Request, out)); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions binder/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ func (*CBORBinding) Name() string {
func (b *CBORBinding) Bind(body []byte, out any) error {
return b.CBORDecoder(body, out)
}

// Reset resets the CBORBinding binder and puts it back to the binder pool.
func (b *CBORBinding) Reset() {
b.CBORDecoder = nil
PutToThePool(&CBORBinderPool, b)

Check warning on line 25 in binder/cbor.go

View check run for this annotation

Codecov / codecov/patch

binder/cbor.go#L23-L25

Added lines #L23 - L25 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ func (b *CookieBinding) Bind(req *fasthttp.Request, out any) error {

return parse(b.Name(), out, data)
}

// Reset resets the CookieBinding binder and puts it back to the binder pool.
func (b *CookieBinding) Reset() {
b.EnableSplitting = false
PutToThePool(&CookieBinderPool, b)

Check warning on line 54 in binder/cookie.go

View check run for this annotation

Codecov / codecov/patch

binder/cookie.go#L52-L54

Added lines #L52 - L54 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ func (b *FormBinding) BindMultipart(req *fasthttp.Request, out any) error {

return parse(b.Name(), out, data.Value)
}

// Reset resets the FormBinding binder and puts it back to the binder pool.
func (b *FormBinding) Reset() {
b.EnableSplitting = false
PutToThePool(&FormBinderPool, b)

Check warning on line 68 in binder/form.go

View check run for this annotation

Codecov / codecov/patch

binder/form.go#L66-L68

Added lines #L66 - L68 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ func (b *HeaderBinding) Bind(req *fasthttp.Request, out any) error {

return parse(b.Name(), out, data)
}

// Reset resets the HeaderBinding binder and puts it back to the binder pool.
func (b *HeaderBinding) Reset() {
b.EnableSplitting = false
PutToThePool(&HeaderBinderPool, b)

Check warning on line 44 in binder/header.go

View check run for this annotation

Codecov / codecov/patch

binder/header.go#L42-L44

Added lines #L42 - L44 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ func (*JSONBinding) Name() string {
func (b *JSONBinding) Bind(body []byte, out any) error {
return b.JSONDecoder(body, out)
}

// Reset resets the JSONBinding binder and puts it back to the binder pool.
func (b *JSONBinding) Reset() {
b.JSONDecoder = nil
PutToThePool(&JSONBinderPool, b)

Check warning on line 25 in binder/json.go

View check run for this annotation

Codecov / codecov/patch

binder/json.go#L23-L25

Added lines #L23 - L25 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ func (b *QueryBinding) Bind(reqCtx *fasthttp.Request, out any) error {

return parse(b.Name(), out, data)
}

// Reset resets the QueryBinding binder and puts it back to the binder pool.
func (b *QueryBinding) Reset() {
b.EnableSplitting = false
PutToThePool(&QueryBinderPool, b)

Check warning on line 58 in binder/query.go

View check run for this annotation

Codecov / codecov/patch

binder/query.go#L56-L58

Added lines #L56 - L58 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/resp_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ func (b *RespHeaderBinding) Bind(resp *fasthttp.Response, out any) error {

return parse(b.Name(), out, data)
}

// Reset resets the RespHeaderBinding binder and puts it back to the binder pool.
func (b *RespHeaderBinding) Reset() {
b.EnableSplitting = false
PutToThePool(&RespHeaderBinderPool, b)

Check warning on line 44 in binder/resp_header.go

View check run for this annotation

Codecov / codecov/patch

binder/resp_header.go#L42-L44

Added lines #L42 - L44 were not covered by tests
}
5 changes: 5 additions & 0 deletions binder/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ func (b *URIBinding) Bind(params []string, paramsFunc func(key string, defaultVa

return parse(b.Name(), out, data)
}

// Reset puts URI binding back to the pool.
func (b *URIBinding) Reset() {
PutToThePool(&URIBinderPool, b)

Check warning on line 23 in binder/uri.go

View check run for this annotation

Codecov / codecov/patch

binder/uri.go#L22-L23

Added lines #L22 - L23 were not covered by tests
}
6 changes: 6 additions & 0 deletions binder/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ func (b *XMLBinding) Bind(body []byte, out any) error {

return nil
}

// Reset puts XML binding back to the pool.
func (b *XMLBinding) Reset() {
b.XMLDecoder = nil
PutToThePool(&XMLBinderPool, b)

Check warning on line 31 in binder/xml.go

View check run for this annotation

Codecov / codecov/patch

binder/xml.go#L29-L31

Added lines #L29 - L31 were not covered by tests
}

0 comments on commit e2e93a4

Please sign in to comment.