Package valuegraph produces a graph representation of any Go value.
See the docs or some examples.
Add "github.com/tcard/valuegraph"
to your import list and then go get
.
The OpenSVG function function, and some methods on Graph, depend on Graphviz's dot
command to be installed in your system.
## Examples
This:
valuegraph.OpenSVG(&Point{1, 2})
Opens this in a browser:
You also have the valuegraph.Make function, which returns a struct you can call less side-effectful methods on.
Recursive data types are handled OK:
v := &List{1, &List{2, &List{3, nil}}}
v.Next.Next.Next = v
valuegraph.OpenSVG(v)
Try it with complex data structures. For example, the go/ast
representation of this code:
package main
// Main function.
func main() {
x := 5
if x < 3 {
fmt.Println("x < 3")
}
}
Yields a certainly big, but navigable, representation. Here's part of it:
Note the path to each element as tooltip (the text that appears when hovering over a node).