mirror of https://github.com/gofiber/fiber.git
🐛 fix: Update binder in form_test (#3336)
* Fix: error binder in form_test * fix: form tag * Fix: error package namepull/3338/head
parent
9e6f4fd408
commit
8e54c8f938
|
@ -28,7 +28,7 @@ Fiber provides several default binders out of the box:
|
||||||
|
|
||||||
### Binding into a Struct
|
### Binding into a Struct
|
||||||
|
|
||||||
Fiber supports binding request data directly into a struct using [gorilla/schema](https://github.com/gorilla/schema). Here's an example:
|
Fiber supports binding request data directly into a struct using [gofiber/schema](https://github.com/gofiber/schema). Here's an example:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Field names must start with an uppercase letter
|
// Field names must start with an uppercase letter
|
||||||
|
|
|
@ -58,19 +58,19 @@ func Benchmark_FormBinder_Bind(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
binder := &QueryBinding{
|
binder := &FormBinding{
|
||||||
EnableSplitting: true,
|
EnableSplitting: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string `query:"name"`
|
Name string `form:"name"`
|
||||||
Posts []string `query:"posts"`
|
Posts []string `form:"posts"`
|
||||||
Age int `query:"age"`
|
Age int `form:"age"`
|
||||||
}
|
}
|
||||||
var user User
|
var user User
|
||||||
|
|
||||||
req := fasthttp.AcquireRequest()
|
req := fasthttp.AcquireRequest()
|
||||||
req.URI().SetQueryString("name=john&age=42&posts=post1,post2,post3")
|
req.SetBodyString("name=john&age=42&posts=post1,post2,post3")
|
||||||
req.Header.SetContentType("application/x-www-form-urlencoded")
|
req.Header.SetContentType("application/x-www-form-urlencoded")
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
|
@ -87,7 +87,7 @@ func parse(aliasTag string, out any, data map[string][]string, files ...map[stri
|
||||||
return parseToStruct(aliasTag, out, data, files...)
|
return parseToStruct(aliasTag, out, data, files...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse data into the struct with gorilla/schema
|
// Parse data into the struct with gofiber/schema
|
||||||
func parseToStruct(aliasTag string, out any, data map[string][]string, files ...map[string][]*multipart.FileHeader) error {
|
func parseToStruct(aliasTag string, out any, data map[string][]string, files ...map[string][]*multipart.FileHeader) error {
|
||||||
// Get decoder from pool
|
// Get decoder from pool
|
||||||
schemaDecoder := decoderPoolMap[aliasTag].Get().(*schema.Decoder) //nolint:errcheck,forcetypeassert // not needed
|
schemaDecoder := decoderPoolMap[aliasTag].Get().(*schema.Decoder) //nolint:errcheck,forcetypeassert // not needed
|
||||||
|
|
2
error.go
2
error.go
|
@ -40,7 +40,7 @@ var (
|
||||||
ErrNoHandlers = errors.New("format: at least one handler is required, but none were set")
|
ErrNoHandlers = errors.New("format: at least one handler is required, but none were set")
|
||||||
)
|
)
|
||||||
|
|
||||||
// gorilla/schema errors
|
// gofiber/schema errors
|
||||||
type (
|
type (
|
||||||
// ConversionError Conversion error exposes the internal schema.ConversionError for public use.
|
// ConversionError Conversion error exposes the internal schema.ConversionError for public use.
|
||||||
ConversionError = schema.ConversionError
|
ConversionError = schema.ConversionError
|
||||||
|
|
Loading…
Reference in New Issue