运行 go build 时出错。带日志回购

Error when running go build . with log repo

我有一个带有 gomod 的 Go 程序,当我 运行 go build . 我得到以下错误:

go: github.com/sirupsen/logrus@v1.4.2 used for two different module paths (github.com/Sirupsen/logrus and github.com/sirupsen/logrus)

我的 mod 看起来像

require (

github.com/Sirupsen/logrus v1.4.2 // indirect
github.com/sirupsen/logrus v1.4.2

…

) 

我添加了以下内容,但没有帮助,知道吗?

replace (
   github.com/Sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2
)

在我的项目代码中我只使用小写的import路径github.com/sirupsen/logrus

尝试删除 //indirect 行,然后 运行

go mod tidy # prune any extraneous requirements + other stuff
go clean # remove object files and cached files
go get -v -u all # update everything related to the dependencies
go build # finger crossed!

github.com/sirupsen/logrus 是 v1.4.2 中 go.mod 文件中指示的正确模块名称 - https://search.gocenter.io/github.com~2Fsirupsen~2Flogrus/info?version=v1.4.2

因此,按照上面的建议,从您的 go.mod 文件和 运行 go mod tidy 中删除对 github.com/Sirupsen/logrus v1.4.2 的引用。此命令会将缺少的版本化依赖项添加到您的 go.mod 文件中。