yamlutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package yamlutil holds the YAML loading helpers shared by the framework's YAML-based configuration.

The main helper resolves an `!include <relative-path>` tag, so a document can pull in other files:

judge: !include judge_audio.yaml
task_messages: !include prompts/greeting.yaml

A path resolves relative to the file that names it, so an included file's own includes resolve against its directory. Paths are not confined to that directory: `..` and absolute paths reach anywhere the process can read. Use these helpers only on trusted documents.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIncludeNotPath reports an !include whose value is not a scalar.
	ErrIncludeNotPath = errors.New("!include expects a file path")
	// ErrIncludeCycle reports a file that includes itself, directly or through
	// the files it includes.
	ErrIncludeCycle = errors.New("!include cycle")
	// ErrIncludeUnavailable reports an !include in a document parsed without
	// include support.
	ErrIncludeUnavailable = errors.New("could not determine a constructor for the tag '!include'")
)

Errors resolving the !include tags of a document.

Functions

func Load

func Load(data []byte, baseDir string) (*yaml.Node, error)

Load parses a YAML document and resolves its !include tags against baseDir, typically the directory of the document being loaded. See ResolveIncludes.

func Parse

func Parse(data []byte) (*yaml.Node, error)

Parse parses a YAML document without include support: an !include tag in it is an ErrIncludeUnavailable. It is how a document from an untrusted source is read, since an include can read any file the process can read.

func ResolveIncludes

func ResolveIncludes(node *yaml.Node, baseDir string) error

ResolveIncludes replaces every `!include <path>` node in the tree with the contents of the file it names.

Paths resolve against baseDir and may reach outside it. An included file is parsed the same way and its own includes resolve against that file's directory, so a fragment's includes work wherever the fragment is included from. A file that includes itself, directly or through the files it includes, is an ErrIncludeCycle. A file may be included more than once.

func Value

func Value(node *yaml.Node, opts ValueOptions) any

Value converts a YAML node into plain Go values: a mapping (a map[string]any unless opts builds something else), []any, string, int, float64, bool, or nil.

Scalars resolve as a YAML 1.1 reader resolves them: `yes`, `no`, `on` and `off` are booleans. A quoted scalar is a string, and an explicitly tagged one follows its tag. `<<` merge keys are applied.

Types

type ValueOptions

type ValueOptions struct {
	// DecimalIntegers resolves only plain decimal integers: `012` and `0x10`
	// stay strings, so a sequence of digits keeps them rather than being read
	// as octal or hex. Left false, integers resolve as a YAML 1.1 reader
	// resolves them: binary, octal, decimal, hexadecimal and sexagesimal.
	DecimalIntegers bool
	// NewMapping builds the value of a mapping from its keys and values, in
	// document order. Nil builds a map[string]any, a key that is not a string
	// being written out as text.
	NewMapping func(keys, values []any) any
}

ValueOptions says how Value reads a document.

Jump to

Keyboard shortcuts

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