Add support for `omitempty` field tag to exclude empty values from queries and headers
Adds support for an omitempty tag.
Main use case is for query parameters where we may not want have empty keys
i.e. /pets?name_pointer=
By adding omitempty to the tag then this the key will not appear in the query string
i.e.
type SearchQuery struct {
NamePointer *string `in:"query=name_pointer,omitempty"`
}
This will create /pets
This has been added to the formencoder so that it will also remove empty headers.
I have picked omitempty as I feel this will feel most natural for engineers as they are likely already used to this syntax with JSON.
Build is failing due to rate limiting in CodeCov - will try a rebuild later.
Codecov Report
Attention: Patch coverage is 77.77778% with 2 lines in your changes are missing coverage. Please review.
Project coverage is 90.70%. Comparing base (
6a628af) to head (a7e1cb0).
| Files | Patch % | Lines |
|---|---|---|
| core/omitempty.go | 50.00% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #107 +/- ##
==========================================
- Coverage 90.78% 90.70% -0.08%
==========================================
Files 34 35 +1
Lines 1530 1539 +9
==========================================
+ Hits 1389 1396 +7
- Misses 97 99 +2
Partials 44 44
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 90.70% <77.77%> (-0.08%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.