Implement nested form binding for structs and arrays
Summary
Addresses issue #2746 by adding support for binding nested structs, arrays, and pointer fields from form data in Echo.
This enhancement allows developers to seamlessly bind complex, deeply nested web form data (such as team.members[0].name=Alice) directly to Go structs with nested slices, pointer fields, and multiple levels of depth.
Changes
- Implements recursive parsing and binding for form keys using dot notation and array indices (e.g.
team.members[0].name). - Supports deeply nested structs, slices, and pointer fields within form binding.
- Updates binder logic to handle keys like
winner.players[1].role=Forwardandloser.leaders[0].name=Charlie. - Adds comprehensive tests for nested, pointer, sparse, and edge-case bindings.
Benefits
- Enables direct binding of complex HTML form data to Go structs, reducing manual mapping in user applications.
- Addresses feature requests such as #2746.
- Maintains backward compatibility with existing flat struct form bindings.
- Improves ergonomics for web forms with nested data in Echo.
Test plan
- [x] All new and existing tests pass
- [x] Linting passes
- [x] Manual verification with sample Echo server and curl requests
- [x] No behavioral changes for existing flat form bindings
Codecov Report
:x: Patch coverage is 81.60920% with 16 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 93.18%. Comparing base (f24aaff) to head (1555007).
:warning: Report is 17 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| bind.go | 81.60% | 11 Missing and 5 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #2834 +/- ##
==========================================
- Coverage 93.25% 93.18% -0.07%
==========================================
Files 39 39
Lines 4652 4753 +101
==========================================
+ Hits 4338 4429 +91
- Misses 218 225 +7
- Partials 96 99 +3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@aldas Could you please approve/enable the workflow run for this PR and re-run CI? I pushed a second commit to fix codecov but the codecov status didn't appear. Thanks.