29
loading...
This website collects cookies to deliver better user experience
go-tree
.GOPATH
to be set (by default, it will be $HOME/go
). You can either run it from within the root directory of your go project (where you go.mod is located), or you can use the -modulePath
flag to pass in a relative or absolute path to the project you want to scan.$ go-tree -modulePath $GOPATH/src/path/to/module/to/scan
-maxDepth
flag to set the maximum recursion level, i.e. how far down the tree to scan. The options are either -1 or an integer above 0, -1 is to indicate no limit and is the default value.$ go-tree -maxDepth -1
-find
flag, which is the whole reason this tool exists. If you specify this flag with the module you would like to find, it will print the full tree for all of the instances of that package in the dependency tree. Note that if you use -find
, the -maxDepth
will be ignored.$ go-tree -find github.com/kapilpau/go-mod-dependency-tree
-find
flag. This route recursively searches each dependency's go.mod to find all of the dependencies for that module and prints out the name and version of the dependency. For this, we read in the go.mod file for your project, find all of the modules in the requires
section and look for the module in the src
or pkg
folders, in your GOPATH
.go.mod
file, we continue through the chains and look for their dependencies. If we can't find a dependency in either location, or it doesn't have a go.mod
file, we end that branch there and move on.dependencyChain
. This struct has two fields, module
(the name of the module currently being scanned) and children
(the dependencies of the current module).dependencyChain
object to pass back. Then, when we have the list of dependencyChain
s for each module, we check the size of the children
field and if it is not empty, we pass it upwards, otherwise we ignore it. The reason we do this check is because we only want to see the branches that end in the module we're looking for.children
of each dependencyChain
and display it as a tree.