Implement validtypes - #45
Conversation
We want to have types we can detect as set or unset, as Zero is a significant value for us. While doing this, we also want to be able to strip unset fields out of the resulting JSON with omitzero. This requires Go 1.24.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a validtypes package that implements wrapper types (ValidInt, ValidFloat, ValidString) to distinguish between intentionally set zero values and unset fields, with support for Go 1.24's omitzero JSON tag. The implementation includes comprehensive JSON marshaling/unmarshaling, text marshaling, and proper handling of "NA" values as invalid states.
Key changes:
- Adds
ValidInt,ValidFloat, andValidStringtypes with set/unset tracking - Implements JSON and text marshaling interfaces with
omitzerotag support - Updates Go version requirement to 1.24.0 for
omitzerofunctionality - Adds CI improvements including test job and
testifylintlinter
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/validtypes/validtypes.go |
Core implementation of valid types with marshaling interfaces |
pkg/validtypes/validtypes_test.go |
Comprehensive test suite covering all valid type functionality |
pkg/parser/parser_test.go |
Adds short test skips and improves test assertions |
go.mod |
Updates Go version to 1.24.0 |
.golangci.yml |
Adds testifylint linter |
.github/workflows/ci.yml |
Adds comprehensive test job with race detection |
Comments suppressed due to low confidence (1)
go.mod:3
- Go 1.24.0 does not exist. The latest Go version as of January 2025 is 1.23.x. This version requirement may cause build failures.
go 1.24.0
|
@gopa-noaa & @randytpierce - I've decided implementing the |
randytpierce
left a comment
There was a problem hiding this comment.
this looks good to me. The testing looks good.
Add a
validtypespackage that implements wrapper types (ValidInt,ValidFloat,ValidString) to distinguish between intentionally set zero values and unset fields. Being able to differentiate between a value that has been deliberately set to zero and a type that has been unset and is at its "zero value" is important for us. Zero values will influence some of the statistics calculated from the MET stat data.To support this, we switch from Go's
omitemptytag to Go 1.24'somitzeroJSON tag asomitzerobehavior can be controlled by implementing.IsZero()methods. The implementation includes comprehensive JSON marshaling/unmarshaling, text marshaling, and proper handling of "NA" values as invalid states.Key changes:
ValidInt,ValidFloat, andValidStringtypes with set/unset trackingomitzerotag supportomitzerofunctionalityThis change does not switch our generator & the linetypes modules to use the new validtypes. That work will come in a follow on PR.