tpath

package
v0.0.0-...-8e4f921 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

tree.go contains functions for traversing and updating a tree constructed from yaml or json.Unmarshal. Nodes in such trees have the form map[interface{}]interface{} or map[interface{}][]interface{}. For some tree updates, like delete or append, it's necessary to have access to the parent node. PathContext is a tree constructed during tree traversal that gives access to ancestor nodes all the way up to the root, which can be used for this purpose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WritePathContext

func WritePathContext(nc *PathContext, value any) error

WritePathContext writes the given value to the Node in the given PathContext.

Types

type PathContext

type PathContext struct {
	// Parent in the Parent of this PathContext.
	Parent *PathContext
	// KeyToChild is the key required to reach the child.
	KeyToChild any
	// Node is the actual Node in the data tree.
	Node any
}

PathContext provides a means for traversing a tree towards the root.

func GetPathContext

func GetPathContext(root any, path util.Path, createMissing bool) (*PathContext, bool, error)

GetPathContext returns the PathContext for the Node which has the given path from root. It returns false and no error if the given path is not found, or an error code in other error situations, like a malformed path. It also creates a tree of PathContexts during the traversal so that Parent nodes can be updated if required. This is required when (say) appending to a list, where the parent list itself must be updated.

func (*PathContext) String

func (nc *PathContext) String() string

String implements the Stringer interface.

Jump to

Keyboard shortcuts

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