yaml

package
v0.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 72

Documentation

Overview

Package yaml converts YAML encodings to and from CUE. When converting to CUE, comments and position information are retained.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(v cue.Value) ([]byte, error)

Encode returns the YAML encoding of v.

func EncodeStream

func EncodeStream(iter cue.Iterator) ([]byte, error)

EncodeStream returns the YAML encoding of iter, where consecutive values of iter are separated with a `---`.

func Extract

func Extract(filename string, src any) (*ast.File, error)

Extract parses the YAML specified by src to a CUE expression. If there's more than one document, the documents will be returned as a list. The src argument may be a nil, string, []byte, or io.Reader. If src is nil, the result of reading the file specified by filename will be used.

The result can be converted to a cue.Value via cue.Context.BuildFile.

func Validate added in v0.0.6

func Validate(b []byte, v cue.Value) error

Validate validates the YAML and confirms it matches the constraints specified by v. For YAML streams, all values must match v.

Types

type Decoder added in v0.15.0

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder converts YAML values to CUE.

func NewDecoder added in v0.15.0

func NewDecoder(path string, src io.Reader) *Decoder

NewDecoder configures a YAML decoder. The path is used to associate position information with each node.

Use the Decoder's Extract method to extract YAML values one at a time. For YAML streams with multiple documents separated by `---`, each call to Extract will return the next document.

func (*Decoder) Extract added in v0.15.0

func (d *Decoder) Extract() (ast.Expr, error)

Extract converts the current YAML value to a CUE ast. It returns io.EOF if the input has been exhausted.

For YAML streams with multiple documents separated by `---`, each call to Extract will return the next document as a separate CUE expression.

The result can be converted to a cue.Value via cue.Context.BuildExpr.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL