登录
首页 >  Golang >  Go问答

查找 Go 模块中依赖项的来源方法

来源:stackoverflow

时间:2024-03-11 17:00:27 385浏览 收藏

小伙伴们对Golang编程感兴趣吗?是否正在学习相关知识点?如果是,那么本文《查找 Go 模块中依赖项的来源方法》,就很适合你,本篇文章讲解的知识点主要包括。在之后的文章中也会多多分享相关知识点,希望对大家的知识积累有所帮助!

问题内容

我有一个 go 模块,比如 github.com/myorg/mymodule,我想更新另一个模块中的版本。但是,如果我尝试 go get -u 它,我会收到 unexpected module path 错误:

> go get -u github.com/myorg/mymodule
go: sourcegraph.com/sourcegraph/[email protected]: parsing go.mod: unexpected module path "github.com/sourcegraph/go-diff"
go get: error loading module requirements

此问题的修复已记录在 https://github.com/sourcegraph/go-diff/issues/35 中:此模块需要导入为 github.com/sourcegraph/go-diff/diff,而不是 github .com/sourcegraph/go-diff

问题是,我不知道在哪里应用此修复 - 即哪个依赖项以错误的方式导入此子依赖项。

特别是,go-diff不会出现在go.mod中,它只出现在go.sum中(在几个不同的模块中):

> grep go-diff go.mod
> grep go-diff go.sum
github.com/pmezard/go-difflib v1.0.0 h1:4dbwde0ngyqobhblqypwsupocmwr5bezik/f1lzbaqm=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:ikh77kofhyxtk1pcrnkkkqftogsbg7gznvy4srdyz/4=
github.com/sergi/go-diff v1.0.0/go.mod h1:0cfeiisq7tuyl3j771mwulgwwju+gofnzx9qamxwzgo=
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7urkmzy0x+p9crk03kfupq2zzqcaefbx8wa8rck=

我尝试过使用 go mod why,但这只是报告不需要该模块:

> go mod why sourcegraph.com/sourcegraph/go-diff
# sourcegraph.com/sourcegraph/go-diff
(main module does not need package sourcegraph.com/sourcegraph/go-diff)

更令人费解的是,错误消息提到了 [email protected],而 go.sum 包含 go-diff v0.5.0

总而言之,如何追踪 go-diff 依赖项的“错误导入”发生在何处,以便我可以更新该模块的版本?


解决方案


我能够通过运行 go get github.com/sourcegraph/go-diff 并在我尝试更新依赖项的模块中添加此替换指令(参见 https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive)来“修补”此问题: p>

replace sourcegraph.com/sourcegraph/go-diff => github.com/sourcegraph/go-diff v0.5.1

之后,go get -u github.com/myorg/mymodule 运行没有错误。

以上就是《查找 Go 模块中依赖项的来源方法》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>