Help us shape the future of Go! Take the 2026 Go Developer Survey

source

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package source reads a SpecArch YAML file into a node tree that keeps the line of every value, and into the plain value the JSON Schema check needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Child

func Child(n *yaml.Node, token string) *yaml.Node

Child returns the value under key in a mapping, or the item at an index in a sequence, following aliases; nil when there is none.

func Deref

func Deref(n *yaml.Node) *yaml.Node

Deref follows an alias.

func EscapeToken

func EscapeToken(s string) string

EscapeToken escapes one JSON pointer token.

func IsScalar

func IsScalar(n *yaml.Node) bool

IsScalar reports whether n is a scalar.

func Items

func Items(n *yaml.Node) []*yaml.Node

Items lists a sequence's items; nil for anything else.

func Key

func Key(n *yaml.Node, key string) *yaml.Node

Key returns the key node for key in a mapping, or nil.

func Pointer

func Pointer(tokens ...string) string

Pointer joins tokens into a JSON pointer, "/" for none.

func Resolve

func Resolve(n *yaml.Node, tokens []string) (*yaml.Node, bool)

Resolve follows a pointer's tokens from n. It returns the deepest node it reached and whether it reached the end. For a mapping key it returns the value node.

func Str

func Str(n *yaml.Node) string

Str returns a scalar's text, or "" for anything else.

func UnescapeToken

func UnescapeToken(s string) string

UnescapeToken reverses EscapeToken.

func ValueOf

func ValueOf(n *yaml.Node) any

ValueOf converts a node tree into plain JSON values, reporting nothing: a repeated key keeps its first value, and a date is its text.

Types

type Doc

type Doc struct {
	Root     *yaml.Node // the top-level mapping, nil when the file did not parse
	Value    any        // the same content as JSON values
	Problems []Problem
}

Doc is one parsed file.

func Parse

func Parse(data []byte) *Doc

Parse reads one YAML document. A syntax error is returned as a Problem, with Root left nil.

type Pair

type Pair struct {
	Key   *yaml.Node
	Value *yaml.Node
}

Pair is one key and value of a mapping.

func Pairs

func Pairs(n *yaml.Node) []Pair

Pairs lists a mapping's entries in document order; nil for anything else.

type Problem

type Problem struct {
	Line    int
	Path    string
	Rule    string
	Message string
}

Problem is something wrong with the YAML itself, found while reading.

Jump to

Keyboard shortcuts

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