tree

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 16 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

func Absolute

func Absolute(path string) string

Absolute is the path two spellings of one file share, so ./a.yaml and a.yaml are one file: the includes' set of files seen and the command line's rule that no output names an input compare paths by it. It falls back to the cleaned path when the working directory cannot be read, so two relative paths still compare by their text.

func Beside

func Beside(file, name string) string

Beside returns the path a name written in file reads: a relative name from file's own directory, so the same file reads the same files from any working directory, and an absolute one as written, because joining it under that directory would name a file that is not the one written. HOCON reads an include's name so, and render reads the origins file and each rpc.proto root a proxyfile names the same way, so every file a proxyfile names is found by one rule.

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

func FromHOCON(path string) (*Node, []string, []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, and returns the files its include statements name, which are inputs of the run as much as the file at path. It returns either the root and the files 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.

The files are found in the text, before the library parses, because the library opens the included files itself and does not say which (resolveInclude and loadIncludeFile, o3co internal/resolver/resolver.go:1615 and 1747, read with os.ReadFile at 1769). The same scan refuses include file(...) before the library opens anything, because the library reads a relative name inside file(...) from the working directory, not beside the including file (resolver.go:1628-1641), so one proxyfile would read different files from different directories.

func FromJSON

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

FromJSON reads a JSON file with the YAML front, which reads JSON as YAML's flow form, with each \/ in a string read as /. JSON writes a slash in a string as / or \/ (RFC 8259, section 7), and go-yaml refuses \/ (found unknown escape character), though YAML 1.2 defines it for JSON's sake (YAML 1.2.2, section 5.7), because go-yaml follows YAML 1.1 there.

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