找到并替换了 Go 模块,但不是必需的
Go module is found and replaced, But not required
我在尝试构建我的 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
中进行调查
问题 44529
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 代码时遇到了一个奇怪的错误。
$ 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
中进行调查
问题 44529
go mod tidy
andgo 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, thego
command would read itsgo.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. (seeimport.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 withgo 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 thego
command does not.)If that network lookup fails, then
go get
will also fall back to replacement version (query.go#Latest()
)