profile picture

Go Archer

January 04, 2025 - programming go tool dependencies

For a long time I have been using github.com/loov/goda whenever I wanted to build a graph of dependencies for a Go project. It is an excelent tool, but I wanted some additional functionality. Usually I use the graph to identify problematic dependencies; for example, if there is a dependency on a database driver, I want to see it all the way up the dependency tree nicely coloured. I looked at the available libraries to analyse the Go code and found that the tooling is rather excelent -- golang.org/x/tools/go/packages allows me not only build the graph of dependencies, but also do a lot of other interesting things, in particular I can find all the concrete and abstract types defined by every package. Resulting tool is gitlab.com/shaydo/go-archer (archer cause it good with arrows). It builds the dependency graph for a module, adds concrete dependencies into picture, such as database drivers or http frameworks, depending on the configuration, and in addition to that calculates abstractness and instability metrics, and the distance from the main line. Dependencies that directed towards low-level packages are highlighted and that allows you to immediately see the issues. The output is in the DOT language, you need graphviz to render it.