tree

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 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 tree is the boundary between a file's syntax and everything that reads it. Each syntax front (YAML and HOCON) fills a Node, and the format check and the decoder read only Nodes, so nothing after this package knows which syntax a file used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key    string
	KeyPos model.Pos
	Value  *Node
}

Entry carries the key's own position so that a problem with the key, such as an unknown key, points at the key, and a problem with the value points at the value.

type Kind

type Kind int
const (
	Scalar Kind = iota + 1
	List
	Map
)

type Node

type Node struct {
	Kind Kind
	Text string
	// Quoted is true for a scalar a YAML reader takes as text whatever it holds: one written in quotes, or as a
	// literal or folded block. The format check refuses one where a number or a boolean is expected, because the JSON
	// Schema an editor checks the file with refuses text there. The HOCON front sets it for every HOCON string, quoted
	// or not, because HOCON types unquoted text as a string.
	Quoted bool
	// NumberOrBool is true for a plain scalar go-yaml takes as a number or a boolean, such as 404, 1.5 or true. The
	// format check refuses one where text is expected, because the JSON Schema refuses a number or a boolean there; the
	// origins and methods files follow the same rule, because one checker serves all three files. go-yaml also takes
	// some YAML 1.1 spellings as numbers (1_000, 0b1, 0X1F) that YAML 1.2's core schema reads as text, so an editor
	// reading YAML 1.2 accepts them as text where the check refuses them: there the check is the stricter side. The
	// HOCON front sets it for every HOCON number and boolean.
	NumberOrBool bool
	Items        []*Node
	Entries      []Entry
	Pos          model.Pos
}

Node is a value of either syntax: a scalar is its text without the quotes (a YAML null is ""), a map keeps its entries in written order.

func FromHOCON added in v1.1.0

func FromHOCON(path string) (*Node, []model.Problem)

FromHOCON reads the HOCON file at path into the tree the YAML front builds for the same gateway, so every check after the tree reads one form. It returns either the root or the problems, never both, as FromYAML does. It takes the path, not the bytes, because the library reads an include relative to the including file only when it opens that file.

func FromYAML

func FromYAML(file string, data []byte) (*Node, []model.Problem)

FromYAML returns either the root or the problems, never both, so no caller can read a tree with a value left out of it.

func (*Node) Entry

func (n *Node) Entry(key string) *Entry

Entry is Get for a reader that also needs the key's position, such as a problem that names the key.

func (*Node) Get

func (n *Node) Get(key string) *Node

Get returns nil when n is nil, is not a Map or lacks the key, so a reader can follow a path such as root.Get("services").Get("shop") and test only the end.

func (*Node) GetText

func (n *Node) GetText(key string) string

GetText is the text of the key's single value, or "" for a key that was not written, so a reader of an optional key needs no nil test. A Text method cannot exist beside the Text field, so the name follows Get.

Jump to

Keyboard shortcuts

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