如何使用 Go Modules 识别依赖链

Gro*_*ify 6 go go-modules

如何识别存在于go.sum但不存在的模块的导入路径go.mod?我想知道哪个模块go.mod正在导入 中列出的模块go.sum,以及它们之间的整个链。

我正在logrus从我的一个模块和我自己的依赖项中删除不推荐使用的模块 , ,并希望确保我自己的任何代码都不再使用它,而其他代码确实使用它。

Go 模块有一个go.mod和一个go.sum文件。在go.sum文件中,github.com/sirupsen/logrus出现了一个未出现在文件中的模块go.mod

当我go.sum通过删除go.sum和运行重新创建文件时go test -v ./...go.sum文件将使用logrus.

中没有直接或间接提及go.mod,例如:

github.com/sirupsen/logrus v1.6.0 // indirect
Run Code Online (Sandbox Code Playgroud)

go mod why 返回以下内容:

$ go mod why github.com/sirupsen/logrus
# github.com/sirupsen/logrus
(main module does not need package github.com/sirupsen/logrus)
Run Code Online (Sandbox Code Playgroud)

go mod why -m 返回以下内容:

$ go mod why -m github.com/sirupsen/logrus
# github.com/sirupsen/logrus
(main module does not need module github.com/sirupsen/logrus)
Run Code Online (Sandbox Code Playgroud)

我怎样才能找出哪个模块go.mod正在导入一个模块,logrus,它在go.sum但不是 中列出go.mod

这是模块:

Ole*_*zov 8

go mod why github.com/sirupsen/logrus
# or 
go mod graph | grep logrus
Run Code Online (Sandbox Code Playgroud)

  • 这将返回“(主模块不需要包 github.com/sirupsen/logrus)”。我已将其添加到该模块的问题中。这是否需要针对每个模块显式运行? (4认同)
  • 间接 deps 并不总是显示,仅当导入模块缺少 go.mod 时,其 deps 才会在 `go.mod` 中。 (2认同)