Documentation ¶
Overview ¶
Package treeprint provides a simple ASCII tree composing tool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var IndentSize = 3
IndentSize is the number of spaces per tree level.
Functions ¶
Types ¶
type NodeVisitor ¶ added in v1.1.0
type NodeVisitor func(item *node)
NodeVisitor function type for iterating over nodes
type StructTreeOption ¶
type StructTreeOption int
const ( StructNameTree StructTreeOption = iota StructValueTree StructTagTree StructTypeTree StructTypeSizeTree )
type Tree ¶
type Tree interface { // AddNode adds a new node to a branch. AddNode(v Value) Tree // AddMetaNode adds a new node with meta value provided to a branch. AddMetaNode(meta MetaValue, v Value) Tree // AddBranch adds a new branch node (a level deeper). AddBranch(v Value) Tree // AddMetaBranch adds a new branch node (a level deeper) with meta value provided. AddMetaBranch(meta MetaValue, v Value) Tree // Branch converts a leaf-node to a branch-node, // applying this on a branch-node does no effect. Branch() Tree // FindByMeta finds a node whose meta value matches the provided one by reflect.DeepEqual, // returns nil if not found. FindByMeta(meta MetaValue) Tree // FindByValue finds a node whose value matches the provided one by reflect.DeepEqual, // returns nil if not found. FindByValue(value Value) Tree // returns the last node of a tree FindLastNode() Tree // String renders the tree or subtree as a string. String() string // Bytes renders the tree or subtree as byteslice. Bytes() []byte SetValue(value Value) SetMetaValue(meta MetaValue) // VisitAll iterates over the tree, branches and nodes. // If need to iterate over the whole tree, use the root node. // Note this method uses a breadth-first approach. VisitAll(fn NodeVisitor) }
Tree represents a tree structure with leaf-nodes and branch-nodes.
func FromStruct ¶
func FromStruct(v interface{}, opt ...StructTreeOption) (Tree, error)
func FromStructWithMeta ¶
func NewWithRoot ¶ added in v1.1.0
NewWithRoot Generates new tree with the given root value
Click to show internal directories.
Click to hide internal directories.