fiber/binder/resp_header.go
RW da0aec0d64
Improve performance for "equalFieldType" function (#3479)
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
2025-05-27 10:48:36 +02:00

44 lines
906 B
Go

package binder
import (
"github.com/gofiber/utils/v2"
"github.com/valyala/fasthttp"
)
// RespHeaderBinding is the respHeader binder for response header.
type RespHeaderBinding struct {
EnableSplitting bool
}
// Name returns the binding name.
func (*RespHeaderBinding) Name() string {
return "respHeader"
}
// Bind parses the response header and returns the result.
func (b *RespHeaderBinding) Bind(resp *fasthttp.Response, out any) error {
data := make(map[string][]string)
var err error
resp.Header.VisitAll(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 RespHeaderBinding binder.
func (b *RespHeaderBinding) Reset() {
b.EnableSplitting = false
}