this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: `go get` Go fields with the json omitempty tag as optional

"omitzero" was added in Go 1.24 as an improvement over "omitempty",
which works in a more intuitive way with structs and arrays,
and supports calling an IsZero method for custom implementations
such as time.Time.

Fixes #3869.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9b4c58544a86cf961434d581012aafd0fd91a2c6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1213251
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+4 -1
+3
cmd/cue/cmd/get_go.go
··· 1474 1474 } 1475 1475 } 1476 1476 1477 + // Go 1.24 added the "omitzero" option to encoding/json, an improvement over "omitempty". 1478 + // Note that, as of mid 2025, YAML libraries don't seem to have picked up "omitzero" yet. 1477 1479 // TODO: also when the type is a list or other kind of pointer. 1478 1480 return hasFlag(tag, "json", "omitempty", 1) || 1481 + hasFlag(tag, "json", "omitzero", 1) || 1479 1482 hasFlag(tag, "yaml", "omitempty", 1) 1480 1483 } 1481 1484
+1 -1
cmd/cue/cmd/testdata/script/get_go_types.txtar
··· 331 331 CustomJSON: #CustomJSON 332 332 } @go(,struct{CustomJSON}) 333 333 optionalOmitEmptyJSON?: string @go(OptionalOmitEmptyJSON) 334 - optionalOmitZeroJSON: time.Time @go(OptionalOmitZeroJSON) 334 + optionalOmitZeroJSON?: time.Time @go(OptionalOmitZeroJSON) 335 335 optionalOmitEmptyYAML?: string @go(OptionalOmitEmptyYAML) 336 336 337 337 // +optional