Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andream16/tree
Go Project to Tree
https://github.com/andream16/tree
go go-ast go-tree tree
Last synced: about 2 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 (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T21:28:41.000Z (over 5 years ago)
- Last Synced: 2024-06-20T09:24:05.781Z (6 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 [![CircleCI](https://circleci.com/gh/nauplio/tree.svg?style=svg)](https://circleci.com/gh/nauplio/tree) [![GoDoc](https://godoc.org/github.com/andream16/tree?status.svg)](https://godoc.org/github.com/andream16/tree) [![Go Report Card](https://goreportcard.com/badge/github.com/andream16/tree)](https://goreportcard.com/report/github.com/andream16/tree) [![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/andream16/tree/master/LICENSE)
Simple go project to tree structure. It supports only go files.
# ???
![alt text](https://raw.githubusercontent.com/AndreaM16/tree/master/assets/structure.png)
```
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()}
```