cuelang / cue

CUE has moved to https://github.com/cue-lang/cue
https://cuelang.org
Apache License 2.0
3.09k stars 171 forks source link

cmd/cue: revisit get go embedding logic #1026

Closed myitcv closed 3 years ago

myitcv commented 3 years ago

What version of CUE are you using (cue version)?

$ cue version
cue version +aa61ee7f linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

https://github.com/cuelang/cue/issues/848 raises a question about whether the CUE generated by cue get go (which will become cue import go under #646) is in fact valid. #848 has been closed as "working as intended" but per https://github.com/cuelang/cue/issues/848#issuecomment-805006596 it does appear to raise a couple of issues/questions.

The cue help get go text talks about the JSON inline tag:

        - embedded structs marked with a json inline tag unify with struct
          definition. For instance, the Go struct

However, this tag does not exist as part of encoding/json, it only exists as a proposal: https://github.com/golang/go/issues/6213. This tag does however exist as part of gopkg.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:

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

verdverm commented 3 years ago

Some thoughts

cueckoo commented 3 years ago

This issue has been migrated to https://github.com/cue-lang/cue/issues/1026.

For more details about CUE's migration to a new home, please see https://github.com/cue-lang/cue/issues/1078.