Documentation
¶
Overview ¶
Package treeprint provides a simple ASCII tree composing tool.
Index ¶
- Variables
- func Repr(v interface{}) string
- type EdgeType
- type FmtFunc
- type MetaValue
- type 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)
- type NodeVisitor
- type StructTreeOption
- type Tree
- type Value
Constants ¶
This section is empty.
Variables ¶
View Source
var IndentSize = 3
IndentSize is the number of spaces per tree level.
Functions ¶
Types ¶
type Node ¶ added in v1.2.0
func (*Node) AddMetaBranch ¶ added in v1.2.0
func (*Node) FindByMeta ¶ added in v1.2.0
func (*Node) FindByValue ¶ added in v1.2.0
func (*Node) FindLastNode ¶ added in v1.2.0
func (*Node) SetMetaValue ¶ added in v1.2.0
func (*Node) VisitAll ¶ added in v1.2.0
func (n *Node) VisitAll(fn NodeVisitor)
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.