How can I identify the import path of a module that exists in go.sum
but not in go.mod
? I'd like to know which module in go.mod
is importing the module listed in go.sum
, and the entire chain between them.
I'm in the process of removing a deprecated module, logrus
, from one of my modules and my own dependencies and want to ensure none of my own code still uses it, and which other code does use it.
The Go module has both a go.mod
and a go.sum
file. In the go.sum
file, a module github.com/sirupsen/logrus
appears that does not appear in the go.mod
file.
When I recreate the go.sum
file by deleting go.sum
and running go test -v ./...
, the go.sum
file is recreated with logrus
.
There is no direct or indirect mention in go.mod
, such as:
github.com/sirupsen/logrus v1.6.0 // indirect
go mod why
returns the following:
$ go mod why github.com/sirupsen/logrus
# github.com/sirupsen/logrus
(main module does not need package github.com/sirupsen/logrus)
go mod why -m
returns the following:
$ go mod why -m github.com/sirupsen/logrus
# github.com/sirupsen/logrus
(main module does not need module github.com/sirupsen/logrus)
How can I find out what module in go.mod
is importing a module, logrus
, which is listed in go.sum
but not go.mod
?
Here's the module:
go.mod
go.sum
You can check to see if there are newer versions of dependencies you're already using in your current module. Use the go list command to display a list of your module's dependencies, along with the latest version available for that module.
As we have learned in Go installation tutorial, standard Go packages like located inside GOROOT directory (where Go is installed). Other project-level dependencies are stored inside GOPATH.
As mentioned above, Go runtime still does use $GOPATH as a download directory of Go packages. To make the Google's saying correct, Go module does not entirely replace GOPATH , but replaces GOPATH for version control and package distribution.
A module dependency is only added to the // indirect section if some package is imported from it, but go mod graph doesn't examine the package import graph at all — it only reports the dependencies between modules, not the packages within those modules. In other words: go mod graph will give you a conservative approximation.
A module is a collection of Go packages stored in a file tree with a go.mod file at its root. The go.mod file defines the module’s module path , which is also the import path used for the root directory, and its dependency requirements , which are the other modules needed for a successful build.
As projects become more complex, one way to keep track of this complexity is to visualize the dependencies used. In GoLand you can do this by using the Show Diagram feature, Ctrl+Alt+Shift+U on Windows/Linux or Cmd+Opt+Shift+U on macOS.
In Golang dependency management, there are several ways of changing the version of a dependency. To start with, if you know the version of a dependency you want, you can simply navigate to the go.mod file in your project and change to your desired dependency version by hand.
go mod why github.com/sirupsen/logrus
# or
go mod graph | grep logrus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With