如何使用GoModules识别依赖链

如何识别存在于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

go mod why 返回以下内容:

$ 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 返回以下内容:

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

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

这是模块:

  • 模块:https : //github.com/grokify/oauth2more
  • go.mod
  • go.sum

回答

go mod why github.com/sirupsen/logrus
# or 
go mod graph | grep logrus

  • indirect deps not always shown, only if go.mod missing for imported module, its deps will be in `go.mod`.

以上是如何使用GoModules识别依赖链的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>