IndentSize is the number of spaces per tree level.
var IndentSize = 3
func Repr(v interface{}) string
type EdgeType string
var ( EdgeTypeLink EdgeType = "│" EdgeTypeMid EdgeType = "├──" EdgeTypeEnd EdgeType = "└──" )
type FmtFunc func(name string, v interface{}) (string, bool)
MetaValue defines any meta value
type MetaValue interface{}
type Node struct { Root *Node Meta MetaValue Value Value Nodes []*Node }
func (n *Node) AddBranch(v Value) Tree
func (n *Node) AddMetaBranch(meta MetaValue, v Value) Tree
func (n *Node) AddMetaNode(meta MetaValue, v Value) Tree
func (n *Node) AddNode(v Value) Tree
func (n *Node) Branch() Tree
func (n *Node) Bytes() []byte
func (n *Node) FindByMeta(meta MetaValue) Tree
func (n *Node) FindByValue(value Value) Tree
func (n *Node) FindLastNode() Tree
func (n *Node) SetMetaValue(meta MetaValue)
func (n *Node) SetValue(value Value)
func (n *Node) String() string
func (n *Node) VisitAll(fn NodeVisitor)
NodeVisitor function type for iterating over nodes
type NodeVisitor func(item *Node)
type StructTreeOption int
const ( StructNameTree StructTreeOption = iota StructValueTree StructTagTree StructTypeTree StructTypeSizeTree )
Tree represents a tree structure with leaf-nodes and branch-nodes.
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) }
func FromStruct(v interface{}, opt ...StructTreeOption) (Tree, error)
func FromStructWithMeta(v interface{}, fmtFunc FmtFunc) (Tree, error)
func New() Tree
New Generates new tree
func NewWithRoot(root Value) Tree
NewWithRoot Generates new tree with the given root value
Value defines any value
type Value interface{}