mirror of
https://github.com/gofiber/fiber.git
synced 2025-07-08 19:48:33 +00:00
Improve performance for "equalFieldType" function OLD: ``` Benchmark_equalFieldType-12 3320424 361.0 ns/op 80 B/op 9 allocs/op ``` NEW: ``` Benchmark_equalFieldType-12 11102847 102.2 ns/op 16 B/op 3 allocs/op ``` + solve the problem with passing on the tag name
44 lines
880 B
Go
44 lines
880 B
Go
package binder
|
|
|
|
import (
|
|
"github.com/gofiber/utils/v2"
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
// CookieBinding is the cookie binder for cookie request body.
|
|
type CookieBinding struct {
|
|
EnableSplitting bool
|
|
}
|
|
|
|
// Name returns the binding name.
|
|
func (*CookieBinding) Name() string {
|
|
return "cookie"
|
|
}
|
|
|
|
// Bind parses the request cookie and returns the result.
|
|
func (b *CookieBinding) Bind(req *fasthttp.Request, out any) error {
|
|
data := make(map[string][]string)
|
|
var err error
|
|
|
|
req.Header.VisitAllCookie(func(key, val []byte) {
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
k := utils.UnsafeString(key)
|
|
v := utils.UnsafeString(val)
|
|
err = formatBindData(b.Name(), out, data, k, v, b.EnableSplitting, false)
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return parse(b.Name(), out, data)
|
|
}
|
|
|
|
// Reset resets the CookieBinding binder.
|
|
func (b *CookieBinding) Reset() {
|
|
b.EnableSplitting = false
|
|
}
|