tree

package module
v0.0.0-...-9c3ac4f Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2016 License: Apache-2.0 Imports: 3 Imported by: 5 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

#Print object as a tree when debugging

How to use

go get github.com/Maxgis/tree
import ("github.com/Maxgis/tree")

tree.Print(ob)

##Print Example


type People struct {
    Name string
	Age  int
	sex  string

	Father   *People
	Children []*People
	Pro      map[string]string
}

func Test_print(t *testing.T) {
	fa := &People{Name: "jim", Age: 44, sex: "man"}
	fa.Pro = make(map[string]string)
	fa.Pro["city"] = "Beijing"
	son := &People{Name: "jimson", Age: 12, sex: "boy"}
	daughter := &People{Name: "jimdaughter", Age: 14, sex: "girl"}
	fa.Children = make([]*People, 2)
	fa.Children[0] = son
	fa.Children[1] = daughter
	son.Father = fa
	Print(fa)
	fmt.Printf("%#v\n", fa)
}

{
  Name:string("jim"),
  Age:int(44),
  sex:string("man"),
  Father:*tree.People(nil),
  Children:[
    {
      Name:string("jimson"),
      Age:int(12),
      sex:string("boy"),
      Father:*tree.People(c8200980f0,reference to each other),
      Children:[],
      Pro:{}(map[string]string)
    }(*tree.People),
    {
      Name:string("jimdaughter"),
      Age:int(14),
      sex:string("girl"),
      Father:*tree.People(nil),
      Children:[],
      Pro:{}(map[string]string)
    }(*tree.People)
  ],
  Pro:{
    city:string("Beijing")
  }(map[string]string)
}(*tree.People)

Original Print

&tree.People{Name:"jim", Age:44, sex:"man", Father:(*tree.People)(nil), Children:[]*tree.People{(*tree.People)(0xc820014280), (*tree.People)(0xc8200142d0)}, Pro:map[string]string{"city":"Beijing"}}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(ob interface{})

func Sprint

func Sprint(ob interface{}) string

Types

type Node

type Node struct {
	Children      []*Node
	FiledType     string
	FiledRealType string
	FieldName     string
	FieldValue    string
	Deep          int
	IsNil         bool
}

Jump to

Keyboard shortcuts

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