The Go API



Go + CUE, it’s over 9000!

CUE has Go API so you can work with Cuelang 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 Cuelang 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

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/cutorials.com repository under code/api

Before you start

cue’s evaluator is not yet safe for concurrency. See the section in cueology/futurology/concurrency




We'll never share your email with anyone else.
2024 Hofstadter, Inc