我开始研究 Go
项目,它使用来自 Github 私有(private)仓库的一些私有(private)模块,每当我尝试运行 go run main.go
它给了我一个低于410 Gone
错误:
verifying github.com/repoURL/go-proto@v2.86.0+incompatible/go.mod: github.com/repoURL/go-proto@v2.86.0+incompatible/go.mod: reading https://sum.golang.org/lookup/github.com/!repoURL/go-proto@v2.86.0+incompatible: 410 Gone
我可以轻松地从终端克隆私有(private)仓库,这意味着我的
ssh
键配置正确。我读了here我需要设置GOPRIVATE
环境变量,但我不知道该怎么做。任何人都可以回答或指向相关教程吗?
Go: v1.13,操作系统: macOS Mojave
最佳答案
简短的回答:
go env -w GOPRIVATE=github.com/repoURL/private-repo
或 如果您想允许您组织的所有私有(private)存储库
go env -w GOPRIVATE=github.com/<OrgNameHere>/*
长答案:
查看"Module configuration for non-public modules"了解更多信息:
The GOPRIVATE environment variable controls which modules the go command considers to be private (not available publicly) and should therefore not use the proxy or checksum database. The variable is a comma-separated list of glob patterns (in the syntax of Go's path.Match) of module path prefixes. For example,
GOPRIVATE=*.corp.example.com,rsc.io/private
causes the go command to treat as private any module with a path prefix matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private, and rsc.io/private/quux.
.
.
The 'go env -w' command (see 'go help env') can be used to set these variables for future go command invocations.
ssh的使用注意事项:
如果您使用 ssh 要访问 git repo(本地托管),您可能需要将以下内容添加到您的
~/.gitconfig
:[url "ssh://git@git.local.intranet/"]
insteadOf = https://git.local.intranet/
对于go
能够访问 git 服务器的命令。
关于go - 如何设置 GOPRIVATE 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58305567/