You can see go mod why
a package exists in the module graph, and go mod graph
shows the module graph, but
there is no command to show the module in the version of the package in the module graph.
go install github.com/jrschumacher/go-mod-what@latest
Usage: go-mod-what [options] <package> [<package> ...]
-help
show help
-modfile string
path to go.mod file (default "./go.mod")
-only-version
only print the version
This will output the module and version of the package golang.org/x/mod v0.21.0
within the go.mod
file.
Example:
$ go-mod-what golang.org/x/mod
golang.org/x/mod v0.21.0
Example with multiple packages:
$ go-mod-what golang.org/x/mod golang.org/x/tools
golang.org/x/mod v0.21.0
golang.org/x/tools v0.1.0
Example with a custom go.mod
file:
$ go-mod-what -modfile /path/to/go.mod golang.org/x/mod
golang.org/x/mod v0.21.0