Skip to content

Implement validtypes - #45

Open
ian-noaa wants to merge 13 commits into
mainfrom
39-handle-intentionally-set-zero-values
Open

Implement validtypes#45
ian-noaa wants to merge 13 commits into
mainfrom
39-handle-intentionally-set-zero-values

Conversation

@ian-noaa

@ian-noaa ian-noaa commented Jul 15, 2025

Copy link
Copy Markdown
Collaborator

Add a validtypes package 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 omitempty tag to Go 1.24's omitzero JSON tag as omitzero behavior 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:

  • Adds ValidInt, ValidFloat, and ValidString types with set/unset tracking
  • Implements JSON and text marshaling interfaces with omitzero tag support
  • Updates Go version requirement to 1.24.0 for omitzero functionality
  • Adds testing to CI
  • Adds the testifylint linter to our linter config

This change does not switch our generator & the linetypes modules to use the new validtypes. That work will come in a follow on PR.

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.
@ian-noaa ian-noaa self-assigned this Jul 15, 2025
@ian-noaa ian-noaa linked an issue Jul 15, 2025 that may be closed by this pull request
@ian-noaa
ian-noaa requested a review from Copilot July 17, 2025 22:01

This comment was marked as outdated.

@ian-noaa
ian-noaa marked this pull request as ready for review July 25, 2025 17:53
@ian-noaa
ian-noaa requested a review from Copilot July 25, 2025 17:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and ValidString types with set/unset tracking
  • Implements JSON and text marshaling interfaces with omitzero tag support
  • Updates Go version requirement to 1.24.0 for omitzero functionality
  • Adds CI improvements including test job and testifylint linter

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

Comment thread pkg/validtypes/validtypes.go Outdated
Comment thread pkg/validtypes/validtypes.go Outdated
Comment thread pkg/validtypes/validtypes.go Outdated
@ian-noaa ian-noaa changed the title Handle intentionally set zero values Implement validtypes Jul 25, 2025
@ian-noaa

Copy link
Copy Markdown
Collaborator Author

@gopa-noaa & @randytpierce - I've decided implementing the validtypes is a great place to split my PR for this zero value work. Could you review this implementation of the validtypes? To keep the PR focused, I'm going to start a new PR for switching generator.go & linetypes to use them.

@randytpierce randytpierce left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me. The testing looks good.

@gopa-noaa gopa-noaa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

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.

Handle intentionally set zero values

4 participants