-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cue: revisit get go embedding logic #1026
Comments
Original reply by @verdverm in cuelang/cue#1026 (comment) Some thoughts
|
I would gently push back against that, because json v2 will support an inline tag (https://pkg.go.dev/github.com/go-json-experiment/json#hdr-JSON_Representation_of_Go_structs), precisely because Go embedding semantics have footguns which are unrelated to encoding semantics. For example, they "promote" methods, which is often undesired when all you want is to inline when encoding. |
Originally opened by @myitcv in cuelang/cue#1026
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
cuelang/cue#848 raises a question about whether the CUE generated by
cue get go
(which will becomecue import go
under #646) is in fact valid. #848 has been closed as "working as intended" but per cuelang/cue#848 (comment) it does appear to raise a couple of issues/questions.The
cue help get go
text talks about the JSONinline
tag:However, this tag does not exist as part of
encoding/json
, it only exists as a proposal: golang/go#6213. This tag does however exist as part ofgopkg.in/yaml.v1
and later major versions.My suggestion would therefore be that we drop this rule for the
inline
tag and instead, by default, adopt the semantics implied by JSON marshalling. Consider this example:https://gist.github.com/myitcv/fbf930c45892bbbc22cced812bfbe346
This demonstrates how:
encoding/json
marshals values of typesS1
andS2
identically, regardless of the presence of theinline
tagencoding/json
respects the embedding ofT1
andT2
in bothS1
andS2
, hence valuess1
ands2
marshal to the same value (seestdout.golden
)cue get go
does behave differently depending on theinline
tag: see how#S1
and#S2
differ inmain_go_gen.cue.golden
But this raises one further question. The
sigs.k8s.io
types referenced in #848 have lots of Yaml tags, which implies these values of these types are fairly regularly marshalled to/from Yaml. Given the proposed change in struct rules above, this might well imply a number of users would be discontent with the default:This seems to point to another requirement: that the caller of
cue get go
should be able to specify the "rules" applied during the conversion. By default,encoding/json
semantics would be applied, with further options available (perhaps in future we could define what it would mean for a Go package to implement and "interface"/API for such conversions?) behind a flag.cc @nyarly and @verdverm from #848
The text was updated successfully, but these errors were encountered: