Library and command-line tool for analyzing and modifying Go code.
Documentation: bitspark.dev/go-tree
- Parse and format Go from source files
- Extract structured package data (functions, types, constants, variables)
- Generate JSON representations fully capturing the codebase
- Configurable and available as CLI and Go library
# Install the library
go get bitspark.dev/go-tree
# Install the CLI tool
go install bitspark.dev/go-tree/cmd/gotree@latest
package main
import (
"fmt"
"bitspark.dev/go-tree/tree"
)
func main() {
// Parse a Go package
pkg, err := tree.Parse("./path/to/package")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Get package info
fmt.Printf("Package: %s\n", pkg.Name())
fmt.Printf("Functions: %v\n", pkg.FunctionNames())
fmt.Printf("Types: %v\n", pkg.TypeNames())
// Format package to a single file
output, err := pkg.Format()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(output)
}
# Parse a package and output to stdout
gotree -src ./path/to/package
# Parse and save to file with options
gotree -src ./path/to/package -out-file output.go -include-tests -preserve-formatting
# Generate JSON documentation
gotree -src ./path/to/package -json -out-dir ./docs/json
# Process multiple packages in batch mode
gotree -batch "/path/to/pkg1,/path/to/pkg2" -json -out-dir ./docs/json
MIT