Closed
Description
If I understand correctly, I think go mod why -m <module-path>
should always show a shortest path unless the target module doesn't exist in the import graph. But it sometimes shows unexpected (main module does not need ...)
, even if the target module definitely exists in the import graph (can be proven by go mod graph
).
Try this (from #36423 (comment)):
$ git clone -q https://github.com/appleboy/gin-jwt.git && cd gin-jwt
$ go mod graph | grep 'github.com/belogik/goes'
github.com/astaxie/beego@v1.11.1 github.com/belogik/goes@v0.0.0-20151229125003-e54d722c3aff
$ go mod why -m github.com/belogik/goes
# github.com/belogik/goes
(main module does not need module github.com/belogik/goes)
I think the expected output of go mod why -m github.com/belogik/goes
here should be:
# github.com/belogik/goes
github.com/appleboy/gin-jwt/v2
github.com/appleboy/gin-jwt/v2.test
github.com/appleboy/gofight/v2
github.com/appleboy/gofight/v2/example
github.com/astaxie/beego
github.com/astaxie/beego/logs/es
github.com/belogik/goes
With this result, we can clearly know exactly how a module enters our import graph. But now we have to know it by using some workarounds like go mod graph | grep '<module-path>'
, this's inconvenient.
/cc @bcmills, @jayconrod