yaml

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 11 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 yaml reads a file of a module, YAML 1.2.2 under its Core schema, into a JSON value, and refuses a file that breaks a rule yaml.*, naming the rule and its place, or that is not YAML 1.2.2 at all (format/README.md, section 4; R45 spec). The check of a module reads each file through it, and the test of vectors reads the vectors of the rules yaml.* (R21).

go.yaml.in/yaml/v4 parses the file into its tree of nodes. It keeps some of YAML 1.1 and lets through some of what YAML 1.2.2 refuses, so passes of this package go around it, each in a file of its own: text.go before the parse, errors.go on its errors, walk.go over its tree for the rules, and layout.go over its tree for what YAML 1.2.2 refuses and v4 reads all the same. Each pass names what of v4 it closes, and a test holds it (R21).

Index

Constants

View Source
const (
	RuleEncoding       = "yaml.encoding"
	RulePrintable      = "yaml.printable"
	RuleSingleDocument = "yaml.single-document"
	RuleNoDirectives   = "yaml.no-directives"
	RuleNoAnchors      = "yaml.no-anchors"
	RuleNoTags         = "yaml.no-tags"
	RuleStringKeys     = "yaml.string-keys"
	RuleUniqueKeys     = "yaml.unique-keys"
	RuleJSONScalars    = "yaml.json-scalars"
	RulePlainStrings   = "yaml.plain-strings"
	RuleCharacters     = "yaml.characters"
)

The rules of section 4 of format/README.md, in its order.

Variables

Rules are the IDs of the rules yaml.*, in the order of section 4.

Functions

func Read

func Read(data []byte) (any, error)

Read reads a file of a module into its JSON value: a map[string]any, []any, string, int64 for a number written with neither a fraction nor an exponent, float64 for any other number, bool, or nil. A file that breaks a rule yaml.*, or is not YAML 1.2.2, gives a *Refusal and no value (format/README.md, section 4).

Types

type Breach

type Breach struct {
	Rule string
	// The place in the file as written: the line and the column, both from 1. The column counts
	// characters, a byte order mark among them, and a byte that is no part of a UTF-8 character
	// counts as one.
	Line, Column int
	Message      string
}

A Breach is one reason a file is refused: a rule it breaks, or, when Rule is empty, that it is not YAML 1.2.2 at all. The format gives that refusal no ID: a file that is not YAML is no module file, whatever its rules say (format/README.md, section 4).

func (Breach) String

func (b Breach) String() string

type Refusal

type Refusal struct {
	Breaches []Breach
}

A Refusal is why a file is not read: every breach found, in the order of their places, and at one place in the order of their rules.

func (*Refusal) Error

func (r *Refusal) Error() string

Jump to

Keyboard shortcuts

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