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 ¶
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") // 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 ¶
Load parses a YAML document and resolves its !include tags against baseDir, typically the directory of the document being loaded. See ResolveIncludes.
func Parse ¶
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 ¶
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.