yaml

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 12 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.

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: 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. A test holds each of them.

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 IDs of the rules yaml.* of the format.

Variables

Rules are the IDs of the rules yaml.*, in the order the format gives them.

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. Any other error is a file that module-kit cannot read, though the format may accept it.

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.

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