go - 如何设置 GOPRIVATE 环境变量

标签 go environment-variables go-modules

我开始研究 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/

相关文章:

go - 使用 GO111MODULE=on 安装 augustoroman/v8 时遇到问题

ruby-on-rails - 如何在开发中禁用ActionMailer?

go - 在 Cobra 命令行工具中,如何为不同的标志使用相同的变量?

go - 如何检测自定义错误

json - GoLang 结构到 JSON 不转换

go - exec.Command和终端执行结果不同

android - 如何使用 gomobile 将多个包绑定(bind)到单个 Java AAR 文件中?

powershell - 如何在 PowerShell 中找到部分路径的潜在源环境变量?

windows - 通过 Powershell 添加 JAVA_HOME 到系统变量 Path

go - Gitlab CI 和 Go 模块