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

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

问题描述

我开始从事Go项目,它使用了Github私有存储库中的一些私有模块,每当我尝试运行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:阅读我可以轻松地从终端克隆私人仓库,这意味着我的ssh密钥配置正确.我在此处中读到我需要设置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?

运行: v1.13,操作系统: macOS Mojave

Go: v1.13, OS: macOS Mojave

推荐答案

简短答案:

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

OR

如果您想允许您组织中的所有私人回购邮件

If you want to allow all private repos from your organization

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


长答案:

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


Long Answer:

Check "Module configuration for non-public modules" for more information:

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天全站免登陆