Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Allow extracting CUE from and injecting CUE into Go code #24

Closed
mpvl opened this issue Apr 4, 2019 · 3 comments
Closed

Allow extracting CUE from and injecting CUE into Go code #24

mpvl opened this issue Apr 4, 2019 · 3 comments
Assignees
Labels
FeatureRequest New feature or request

Comments

@mpvl
Copy link
Contributor

mpvl commented Apr 4, 2019

This is a tracking issue related to extracting CUE from Go code. The functionality in this issue focusses on use cases where Go is used as the source of truth. Issue #6 focusses on generating Go assuming that CUE is used as the source of truth.

injection:
Allow annotation of Go types with additional CUE constraints and provide a simple API to validate and complete Go values.

extraction:
The primary extraction method looks at struct definitions in Go code, determines how these would be interpreted by the encoding/json package, and then generates CUE definitions for such structs.
In addition, we can extract CUE annotations used in Go code for validation to augment such definitions.

mpvl added a commit that referenced this issue Apr 6, 2019
Optional fields are crucial in making it manageable
to work with very large struct types, like those of
Kubernetes. Without optional fields, the fields of
a simple K8s configuration  would be lost in the noise
compared to the default value of every expanded field.

It also allows writing:
  foo?: MyStruct
instead of
  foo: *null | MyStruct
which gets old quickly when one has hundreds of
such fields.

Updates #24

Change-Id: I856d9a3e20584750b911784924fa18d4557b9920
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1700
Reviewed-by: Marcel van Lohuizen <[email protected]>
mpvl added a commit that referenced this issue Apr 6, 2019
Also allow any CUE as literal value for builtins.
This, in turn, is necessary to define some useful core
types (like time.Time) as well as to give better support
for the scripting layer, allowing better abstractions
for tools.

Updates #24

Change-Id: Icdcf7dfe7330bcc0efef437689503a84bcf3567c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1721
Reviewed-by: Marcel van Lohuizen <[email protected]>
mpvl added a commit that referenced this issue Apr 6, 2019
For now, just the time.Time type is added, which
is an often-used type in the type of Go structs that
one may want to map to CUE.

Updates #24

Change-Id: Ied688f7dd355006e4515520f22dd40b646703c6f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1722
Reviewed-by: Marcel van Lohuizen <[email protected]>
mpvl added a commit that referenced this issue Apr 6, 2019
Update #24

Change-Id: I3589937d0ddf46d25938bcc8e4093542c0668ca7
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1787
Reviewed-by: Marcel van Lohuizen <[email protected]>
@mpvl mpvl self-assigned this Apr 6, 2019
mpvl added a commit that referenced this issue Apr 8, 2019
Note that this is different from converting a value.

Updates #24

Change-Id: Ibb83c1e2169ee637c549d2961f54954581188503
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1788
Reviewed-by: Marcel van Lohuizen <[email protected]>
@mpvl mpvl added the FeatureRequest New feature or request label Apr 8, 2019
mpvl added a commit that referenced this issue Apr 19, 2019
Updates #24

Change-Id: Ib6e173af2b8a805d2109bf291048a9fca8b72d61
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1789
Reviewed-by: Marcel van Lohuizen <[email protected]>
mpvl added a commit that referenced this issue Apr 19, 2019
Update #24

Change-Id: Ief47b7295249354d5eafbe0bcf33ea26dd6dfdc7
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1723
Reviewed-by: Marcel van Lohuizen <[email protected]>
@Meai1
Copy link

Meai1 commented Jul 5, 2019

I didnt want to make a new issue for this but this from the docs doesnt currently create any files:

$ cue get go k8s.io/api/core/v1
$ cue get go k8s.io/api/extensions/v1beta1
$ cue get go k8s.io/api/apps/v1beta1

All it does is create folders with no files in them.

EDIT: Ok it works after doing a go get first, but there was no error message that the underlying go package was missing.

@errordeveloper
Copy link

@Meai1 I stumbled upon that too, sounds like a bug in the docs!

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#24.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants