Documentation ¶
Overview ¶
Package gtree provides tree-structured output.
Example ¶
var root *gtree.Node root = gtree.NewRoot("root") root.Add("child 1").Add("child 2") root.Add("child 1").Add("child 3") child4 := root.Add("child 4") var child7 *gtree.Node child7 = child4.Add("child 5").Add("child 6").Add("child 7") child7.Add("child 8") buf := &bytes.Buffer{} if err := gtree.ExecuteProgrammably(buf, root); err != nil { panic(err) } fmt.Println(buf.String())
Output: root ├── child 1 │ ├── child 2 │ └── child 3 └── child 4 └── child 5 └── child 6 └── child 7 └── child 8
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNilNode is returned if the argument *gtree.Node of ExecuteProgrammably function is nill. ErrNilNode = errors.New("nil node") // ErrNotRoot is returned if the argument *gtree.Node of ExecuteProgrammably function is not root of the tree. ErrNotRoot = errors.New("not root node") )
Functions ¶
Types ¶
type Node ¶
type Node struct { Text string `json:"value" yaml:"value" toml:"value"` Children []*Node `json:"children" yaml:"children" toml:"children"` // contains filtered or unexported fields }
Node is main struct for gtree.
type OptFn ¶ added in v6.1.0
type OptFn func(*config) error
OptFn is functional options pattern
func BranchFormatIntermedialNode ¶ added in v6.0.2
BranchFormatIntermedialNode returns function for branch format.
func BranchFormatLastNode ¶ added in v6.0.2
BranchFormatLastNode returns function for branch format.
func EncodeJSON ¶ added in v6.1.0
func EncodeJSON() OptFn
EncodeJSON returns function for output json format.
func EncodeTOML ¶ added in v6.2.0
func EncodeTOML() OptFn
EncodeTOML returns function for output toml format.
func EncodeYAML ¶ added in v6.2.0
func EncodeYAML() OptFn
EncodeYAML returns function for output yaml format.
func IndentFourSpaces ¶
func IndentFourSpaces() OptFn
IndentFourSpaces returns function for four spaces indent input.
func IndentTwoSpaces ¶
func IndentTwoSpaces() OptFn
IndentTwoSpaces returns function for two spaces indent input.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.