Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(binding): add CustomDecimal type for parsing decimal numbers wit… #4129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aydinomer00
Copy link

Description

This commit adds support for parsing decimal numbers that start with a dot (e.g. ".1") in query parameters and form data. It implements the BindUnmarshaler interface to handle this special case.

Changes

  • Added CustomDecimal type that embeds decimal.Decimal
  • Implemented the BindUnmarshaler interface to parse decimal values with leading dots
  • Added comprehensive tests for validation
  • Provided an example usage under examples/custom-decimal

Example Usage

type QueryParams struct {
    Amount binding.CustomDecimal `form:"amount"`
}

// With this change:
// GET /amount?amount=.1   -> parses as "0.1"
// GET /amount?amount=1.23 -> parses as "1.23"
// Invalid formats return appropriate errors


Testing
Added unit tests covering various decimal formats (leading dot, valid decimals, invalid strings, etc.)
All tests are passing
Manually tested with the example application and verified
Fixes #4089

Checklist

 I have performed a self-review of my code
 I have added tests for my changes
 My changes generate no new warnings
 I have added an example demonstrating the functionality

…h leading dot

This commit adds support for parsing decimal numbers that start with a dot
(e.g. '.1') in query parameters and form data. It implements the
BindUnmarshaler interface to handle this special case.

Fixes gin-gonic#4089
@aydinomer00
Copy link
Author

Is there any update or feedback regarding this PR? I’d be happy to make any improvements or adjustments if needed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant