https://github.com/andream16/tree
Go Project to Tree
https://github.com/andream16/tree
go go-ast go-tree tree
Last synced: 5 months ago
JSON representation
Go Project to Tree
- Host: GitHub
- URL: https://github.com/andream16/tree
- Owner: andream16
- License: mit
- Created: 2018-10-23T20:15:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T21:28:41.000Z (about 6 years ago)
- Last Synced: 2025-02-17T14:53:56.966Z (5 months ago)
- Topics: go, go-ast, go-tree, tree
- Language: Go
- Homepage:
- Size: 1.19 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tree [](https://circleci.com/gh/nauplio/tree) [](https://godoc.org/github.com/andream16/tree) [](https://goreportcard.com/report/github.com/andream16/tree) [](https://raw.githubusercontent.com/andream16/tree/master/LICENSE)
Simple go project to tree structure. It supports only go files.
# ???

```
package mainimport (
"fmt"
"go/ast""github.com/andream16/tree"
)func main() {
out, err := tree.Get("examples/example", &tree.Node{})
if err != nil {
panic(err)
}fmt.Println(out.Name) // example
fmt.Println(out.Leafs[0].Name) // somefile.go
fmt.Println(out.Leafs[0].Path) // examples/example/somefile.go
fmt.Println(out.Nodes[0].Name) // example/subexample
fmt.Println(out.Nodes[0].Leafs[0].Name) // someotherfile.go
fmt.Println(out.Nodes[0].Leafs[0].Path) // examples/example/subexample/someotherfile.goerr = out.Leafs[0].Ast()
if err != nil {
panic(err)
}ast.Inspect(out.Leafs[0].SyntaxTree, func(n ast.Node) bool {
var s string
switch x := n.(type) {
case *ast.BasicLit:
s = x.Value
case *ast.Ident:
s = x.Name
}
if s != "" {
fmt.Printf("%s\n", s) // example
}
return true
})// example
// | somefile.go
// example/subexample
// | someotherfile.go
out.Print()}
```