gomodgraph
gomodgraph provides support for understanding go dependencies. The
current sub commands are:
graph
graph uses go mod graph to obtain the module dependency
graph which can be displayed or queried in simple ways.
In particular:
- the graph can be output as a dot file
- the graph can be flattened in both 'directions', that
is given a starting point all dependencies or all dependents
can be enumerated as a tree (with cycles detected). The
flattened trees can be queried for the presence of a given
module.
- the graph can be visualized in a browser as either
a dependency wheel or an interactive tree. Both are
initial prototypes at the moment but still useful, especially
the interactive tree since it supports pan/zoom and collapsing.
examples
Dot graph of all dependencies for the current module:
go run github.com/cosnicolaou/godep graph --dot . > mymodule.dot
sfdp -Tpdf -o mymodule.pdf mymodule.dot
Simple display of dependency hierarchy:
go run github.com/cosnicolaou/godep graph query
Find all dependencies introduced by golang.org/x/tools:
go run github.com/cosnicolaou/godep graph query --start=golang.org/x/tools
Find all dependents that use golang.org/x/tools:
go run github.com/cosnicolaou/godep graph query --dependencies=false --start=golang.org/x/tools
Find all dependents that use golang.org/x/tools:
go run github.com/cosnicolaou/godep graph query --dependencies=false --start=golang.org/x/tools
Find all dependents that use golang.org/x/tools which occur on a path that includes google.golang.org/grpc:
go run github.com/cosnicolaou/godep graph query --dependencies=false --start=golang.org/x/tools --contains=google.golang.org/grpc
Several visualizations are available, including a dependency wheel, code flower and ...
go run . graph dependency-wheel > dep-well.html && open dep-well.html
go run . graph itree > interactive-tree.html && open interactive-tree.html
TODO
- add a command to display detected cycles rather than just
breaking them
- add dot output generation for the flattened trees as well
as the graph
- add an interactive visualizer for dependencies (likely using
d3)