如何设置 GOPRIVATE 环境变量 [英] How to set GOPRIVATE environment variable

查看:51
本文介绍了如何设置 GOPRIVATE 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始从事一个 Go 项目,它使用来自 Github 私有 repos 的一些私有模块,每当我尝试运行 go run main.go 时,它都会给我以下信息410 Gone 错误:

I started working on a Go project and it uses some private modules from Github private repos and whenever I try to run go run main.go it gives me a below 410 Gone error:

验证 github.com/repoURL/go-proto@v2.86.0+incompatible/go.mod: github.com/repoURL/go-proto@v2.86.0+incompatible/go.mod: 阅读 https://sum.golang.org/lookup/github.com/!repoURL/go-proto@v2.86.0+不兼容: 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

我可以轻松地从终端克隆私人仓库,这意味着我的 ssh 密钥配置正确.我读了 here 我需要设置 GOPRIVATE环境变量,但我不知道该怎么做.

I can easily clone private repo from terminal which means my ssh keys are configured correctly. I read here that I need to set GOPRIVATE environment variable but I am not sure how to do that.

任何人都可以回答或指向相关教程吗?

Can anyone answer or point to the relevant tutorial?

Go: v1.13,操作系统: macOS Mojave

Go: v1.13, OS: macOS Mojave

推荐答案

简答:

go env -w GOPRIVATE=github.com/repoURL/private-repo

如果您想允许来自您的组织的所有私有存储库

If you want to allow all private repos from your organization

go env -w GOPRIVATE=github.com/<OrgNameHere>/*


长答案:

查看非公共模块的模块配置"了解更多信息:

GOPRIVATE 环境变量控制 go 命令认为哪些模块是私有的(不能公开使用),因此不应使用代理或校验和数据库.该变量是以逗号分隔的模块路径前缀的 glob 模式列表(在 Go 的 path.Match 的语法中).例如,

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

导致 go 命令将路径前缀匹配任一模式的任何模块视为私有模块,包括 git.corp.example.com/xyzzy、rsc.io/private 和 rsc.io/private/quux.

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.

..

go env -w"命令(参见go help env")可用于为将来的 go 命令调用设置这些变量.

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:


Note on the usage of ssh:

If you use ssh to access git repo (locally hosted), you might want to add the following to your ~/.gitconfig:

[url "ssh://git@git.local.intranet/"]
       insteadOf = https://git.local.intranet/

go 命令能够访问 git 服务器.

for the go commands to be able to access the git server.

这篇关于如何设置 GOPRIVATE 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆