Skip to content

Commit

Permalink
πŸ› fix: Update binder in form_test (#3336)
Browse files Browse the repository at this point in the history
* Fix: error binder in form_test

* fix: form tag

* Fix: error package name
  • Loading branch information
devhaozi authored Mar 4, 2025
1 parent 9e6f4fd commit 8e54c8f
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion binder/README.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ Fiber provides several default binders out of the box:

### 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
// Field names must start with an uppercase letter
10 changes: 5 additions & 5 deletions binder/form_test.go
Original file line number Diff line number Diff line change
@@ -58,19 +58,19 @@ func Benchmark_FormBinder_Bind(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

binder := &QueryBinding{
binder := &FormBinding{
EnableSplitting: true,
}

type User struct {
Name string `query:"name"`
Posts []string `query:"posts"`
Age int `query:"age"`
Name string `form:"name"`
Posts []string `form:"posts"`
Age int `form:"age"`
}
var user User

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")

b.ResetTimer()
2 changes: 1 addition & 1 deletion binder/mapping.go
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ func parse(aliasTag string, out any, data map[string][]string, files ...map[stri
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 {
// Get decoder from pool
schemaDecoder := decoderPoolMap[aliasTag].Get().(*schema.Decoder) //nolint:errcheck,forcetypeassert // not needed
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ var (
ErrNoHandlers = errors.New("format: at least one handler is required, but none were set")
)

// gorilla/schema errors
// gofiber/schema errors
type (
// ConversionError Conversion error exposes the internal schema.ConversionError for public use.
ConversionError = schema.ConversionError

1 comment on commit 8e54c8f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 8e54c8f Previous: 42d921d Ratio
Benchmark_Ctx_Send 6.549 ns/op 0 B/op 0 allocs/op 4.364 ns/op 0 B/op 0 allocs/op 1.50
Benchmark_Ctx_Send - ns/op 6.549 ns/op 4.364 ns/op 1.50
Benchmark_Utils_GetOffer/1_parameter 218.6 ns/op 0 B/op 0 allocs/op 134.2 ns/op 0 B/op 0 allocs/op 1.63
Benchmark_Utils_GetOffer/1_parameter - ns/op 218.6 ns/op 134.2 ns/op 1.63
Benchmark_Middleware_BasicAuth - B/op 80 B/op 48 B/op 1.67
Benchmark_Middleware_BasicAuth - allocs/op 5 allocs/op 3 allocs/op 1.67
Benchmark_Middleware_BasicAuth_Upper - B/op 80 B/op 48 B/op 1.67
Benchmark_Middleware_BasicAuth_Upper - allocs/op 5 allocs/op 3 allocs/op 1.67
Benchmark_CORS_NewHandler - B/op 16 B/op 0 B/op +∞
Benchmark_CORS_NewHandler - allocs/op 1 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerSingleOrigin - B/op 16 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerSingleOrigin - allocs/op 1 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerPreflight - B/op 104 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerPreflight - allocs/op 5 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerPreflightSingleOrigin - B/op 104 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerPreflightSingleOrigin - allocs/op 5 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerPreflightWildcard 1021 ns/op 104 B/op 5 allocs/op 674.6 ns/op 0 B/op 0 allocs/op 1.51
Benchmark_CORS_NewHandlerPreflightWildcard - ns/op 1021 ns/op 674.6 ns/op 1.51
Benchmark_CORS_NewHandlerPreflightWildcard - B/op 104 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerPreflightWildcard - allocs/op 5 allocs/op 0 allocs/op +∞
Benchmark_Middleware_CSRF_GenerateToken - B/op 515 B/op 322 B/op 1.60
Benchmark_Middleware_CSRF_GenerateToken - allocs/op 10 allocs/op 6 allocs/op 1.67

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.