🧹 chore: Handle defaults only when field missing#25
Hidden character warning
Conversation
WalkthroughThe Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #25 +/- ##
==========================================
+ Coverage 88.31% 88.39% +0.07%
==========================================
Files 4 4
Lines 933 939 +6
==========================================
+ Hits 824 830 +6
Misses 91 91
Partials 18 18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR adjusts the decoder's default value handling so that default values for boolean fields are only applied when the form field is missing, instead of overwriting provided values. Key changes include:
- Updating setDefaults to accept the input source and a prefix for proper field detection.
- Adding a helper function fieldProvided to determine if a field was supplied.
- Introducing a new test to validate the bool default behaviour.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| decoder_test.go | Added test for verifying bool default is applied only if missing. |
| decoder.go | Modified setDefaults signature and logic; added fieldProvided. |
| return !v.IsZero() && v.Type().Kind() == reflect.Ptr && v.Elem().Type().Kind() == reflect.Struct | ||
| } | ||
|
|
||
| func fieldProvided(src map[string][]string, prefix string, f *fieldInfo) bool { |
There was a problem hiding this comment.
[nitpick] Consider adding a doc comment for the fieldProvided function to explain its purpose and the expected format of the prefix argument, enhancing maintainability.
benchmark is not really changed |
Summary
setDefaultsto check if form field is provided before applying default valuesfieldProvidedhelperTesting
go test ./...Summary by CodeRabbit
Bug Fixes
Tests