2020年10月16日 星期五

[ 常見問題 ] How to set GOPRIVATE environment variable

 Source From Here

Question
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:
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

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.

HowTo

Short Answer:
# 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:
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,
  1. 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.

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:
  1. [url "ssh://git@git.local.intranet/"]  
  2.        insteadOf = https://git.local.intranet/  
for the go commands to be able to access the git server.

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...