mirror of
https://github.com/gofiber/fiber.git
synced 2025-07-09 12:09:58 +00:00
* feat: Add All method to Bind This commit introduces a new `All` method to the `Bind` struct, enabling the binding of request data from multiple sources (URI parameters, body, query parameters, headers, and cookies) into a single struct. The `All` method iterates through the available binding sources, applying them in a predefined precedence order. It merges the values from each source into the output struct, only updating fields that are currently unset. Changes: - Added `All` method to `Bind` struct. - Added `mergeStruct` helper function to merge struct values. - Added `isZero` helper function to check if a value is zero. - Added a test case for the `All` method in `bind_test.go` to validate its functionality. * feat: Enhance Bind.All with comprehensive testing and configuration The changes include: - Added `RequestConfig` struct to encapsulate request configuration (ContentType, Body, Headers, Cookies, Query). - Implemented `ApplyTo` method on `RequestConfig` to apply the configuration to the context. - Created multiple test cases for `Bind.All` covering successful binding, missing fields, overriding query parameters, and form binding. - Added a test case `Test_Bind_All_Uri_Precedence` to validate the precedence of URI parameters. - Added benchmark test `BenchmarkBind_All` to measure the performance of the `Bind.All` method. - Refactored the `TestBind_All` to use the new `RequestConfig` and assertion libraries. * fix: Correct form binding in Test_Bind_All * refactor: Improve Bind.All test and struct field ordering - Reordered fields in `RequestConfig` and `User` structs for field alignment - Updated `Test_Bind_All` to use `require.NoError` for more robust error checking. - Corrected header key casing in `Test_Bind_All` to `X-User-Role` to match the struct tag. - Added `t.Parallel()` to the test function to enable parallel test execution. * feat: Document Bind.All function in API documentation This commit adds documentation for the `Bind.All` function to the API documentation. The documentation includes: - A description of the function's purpose and precedence order for binding data from different sources (URI, body, query, headers, cookies). * docs: lint Bind.All documentation * fix: Update parameter tags from 'param' to 'uri' in bind_test.go * fix: Update parameter tags from 'param' to 'uri' in bind.md * test: Replace assert with require in bind_test.go * feat: Add support for unified binding with defined precedence order in whats_new.md --------- Co-authored-by: RW <rene@gofiber.io>