feat: add support for encoding into URL query parameters#40
feat: add support for encoding into URL query parameters#40quagmt merged 2 commits intoquagmt:masterfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #40 +/- ##
=======================================
Coverage 96.40% 96.41%
=======================================
Files 5 5
Lines 1921 1924 +3
=======================================
+ Hits 1852 1855 +3
Misses 46 46
Partials 23 23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@mdawar Thanks for PR. This seems okay to me as long as it doesn't add external dependency. However, I'm thinking it might bloat the library if we implement non-std interfaces because there's a lot of them |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for encoding the Decimal type into URL query parameters by implementing the query.Encoder interface from the go-querystring package.
- Added the EncodeValues method for Decimal in codec.go.
- Added a new set of tests in codec_test.go to verify encoding consistency.
- Updated the .golangci.yaml configuration for updated linting requirements.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| codec.go | Implements the EncodeValues method for Decimal to support URL query parameter encoding. |
| codec_test.go | Introduces TestEncodeValues to validate that Decimal values are correctly encoded. |
| .golangci.yaml | Updates configuration settings to align with new linting standards. |
Comments suppressed due to low confidence (1)
codec_test.go:416
- Consider adding test cases to verify the omitempty behavior by checking that a Decimal field with a zero value is omitted from the URL query parameters when tagged with omitempty.
func TestEncodeValues(t *testing.T) {
|
@quagmt Thank you for reviewing the PR. Yes this is just an interface implementation and there are no external dependencies. You're totally right about the third party interfaces, there are a lot of them for sure. What motivated this addition is that decimal values are commonly used in financial apps (especially in crypto) where signing URL encoded query parameters is typical. For example, here’s a reference from Binance: This isn’t specific to Binance, many exchange APIs use similar schemes. So while not essential, this feature is useful in practice. That said, I’m already using a fork with this change, so feel free to close the PR if it doesn't fit your vision for the library. Thanks again. |
|
@mdawar I'll keep this PR open for a while to see if someone have the same issue, then I think we can consider further |
|
@quagmt I have a use case that would benefit from this addition |
|
@mdawar It seems there’s demand for this feature. Can you add test cases for both |
|
@quagmt are you sure about the tests for The current implementation does not need more than the current test where we only check that the |
|
This pull request adds support for encoding the
Decimaltype into a URL query parameter using thego-querystringpackage.It adds an implementation for the
Encoderinterface:Example usage:
Maybe this is a niche use case, but it doesn't add any overhead to the package.