找到并替换了 Go 模块,但不是必需的

标签 go go-modules

当我尝试构建我的 go 代码时,我遇到了一个奇怪的错误。

$ make install
go version go1.16 windows/amd64
bin/check_go_version 1.14.4
plugin/loader/preload.sh > plugin/loader/preload.go
go fmt plugin/loader/preload.go >/dev/null
go install "-asmflags=all='-trimpath=C:\Users\Deepak Dash\go\src'" "-gcflags=all='-trimpath=C:\Users\Deepak Dash\go\src'" -ldflags="-X "github.com/ipfs/go-ipfs".CurrentCommit=8f9a2b7-dirty" ./cmd/ipfs
cmd\ipfs\daemon.go:32:2: module github.com/ipfs/go-saas-endpoint provides package github.com/ipfs/go-saas-endpoint and is replaced but not required; to add it:
        go get github.com/ipfs/go-saas-endpoint
make: *** [cmd/ipfs/Rules.mk:37: cmd/ipfs-install] Error 1

我以前曾与 go.mods 合作过。我已经用本地模块替换了 GitHub 包。它正在检测本地包。
谢谢,
迪帕克冲刺

最佳答案

这是一个 Go 1.16 问题,目前在 golang/go issue 44529 中进行调查。
它包括Jay Conrod's comment :

go mod tidy and go get may both hit the network to look up imported packages that aren't provided by any required module.
If a module is replace locally, the go command will look there first, but I think it may still go out to the network for other prefixes of the module path.

Instead, you can add a requirement on a non-existent version while replacing that version:

go mod edit -require example.com/mod@v0.0.0-local -replace example.com/mod@v0.0.0-local=../local

Adding a replacement, even one without a version on the left side, doesn't automatically add that module to the build list.
If it did, the go command would read its go.mod file and apply its requirements. That could influence selected versions of other modules, even if the replaced module didn't provide any packages.


Bryan C. Mills from Google adds :

go mod tidy should never do a network lookup if it could add a replaced module instead. (see import.go#queryImp())

go get, on the other hand, will perform a network lookup in order to identify the true latest version, taking your replacements into account (query.go#Versions()), and then that version will be replaced instead of downloaded.
It does that so that the latest version added by go get is always consistent with go list -m [⋯]@latest, and so that (if possible) your require directive always specifies a valid version for downstream consumers (if any), so that they won't break when they require your module. (Downstream consumers will not pick up your replace directives, so they need a valid version.)

If you are not using a proxy for the repo in question, that lookup may involve cloning the upstream repo. So that can be a pretty expensive operation. (Note that the official distributions of the go command use proxy.golang.org by default, but the Fedora fork of the go command does not.)

If that network lookup fails, then go get will also fall back to replacement version (query.go#Latest())

关于找到并替换了 Go 模块,但不是必需的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66469396/

相关文章:

git - Go mod 用私有(private) fork 替换依赖

Go Modules 无法识别 GOPATH 下的文件

go - 使用 'go build' 获取依赖项,即使它们位于 vendor/中

go - 在 monorepo 环境中发布 go 模块

string - 为 unicode 字母写一个 toUpper 函数

go - 如果修改信号处理程序中的ctx.rip和ctx.rsp会发生什么

go - 如何重置或丢弃缓冲数据

go - 找不到提供包的模块

我可以在 Google App Engine 上使用 CGo 吗?

go - 如何为 gRPC TLS 连接设置 docker-compose 容器?