Cue's API

Cue has Go API so you can work with Cue from Go programs. It offers more granularity and sophistication than the cli. There are also capabilities only accessible from Cue’s Go API. This section will take you on a tour through Cue’s Go API, showing you how to do Cue things in Go. You will learn how to:

  • Load Cue code into Cue values
  • Print Cue values with various options
  • Extract Cue values, loop over fields and lists
  • Extract and work with Cue attributes
  • Unify and validate Cue and Go values
  • Decode to, and encode from, Cue and Go values
  • Validate, constrain, and complete Go values

Working with the encodings is in the integrations section.

These links will be handy as you learn and work with Cue’s Go API.

cue - The main API for working with Values
cue/load - Load Cue instances in Go
cue/build - Build your loaded Cue instances
cue/format - Format and print Cue Values
cuego - Validate, constrain, or complete Go values
encoding - Parse and generate Yaml, JSON, Protobuf, JSONSchema, and OpenAPI*

* operations depend on the codec, some only work one direction

The examples in these sections can be found in hofstadter-io/ repository under code/api

2021 Hofstadter, Inc