The CUE Context
Working with CUE from Go starts with
Code is compiled and values are built using a context.
You will see the basic methods for
and later pages will increase the sophistication.
When working with multiple values, they should come from the same runtime. This requirement will be removed in a future version.
Compiling with Context
This is the simplest program to print a CUE value. It will print the first error message if you have one.
Compiling with a Scope
If you have schemas in one string and values in another,
you can use the
cue.Scope option to provide a “context” for the
Encoding Values from Go
You can also transform your Go types and values into CUE values. We can control the output with struct tags. Note that
- Only public members will be encoded by CUE.
- We can use
omitemptyto prevent output, but this impacts the type encoding as well.
- Numerical types have some quirks we’ll talk about later. CUE normally uses
- Details can be found in the pkg.go.dev cue.Context.Encode docs.