我想在另一个 GoLang 项目中使用托管在 GitHub 上的私有存储库。
我做了什么:
然后做了:
git config --global url." https://xxxxxx:ACCESS_TOKEN@github.com " .insteadOf " https://github.com "
使用“xxxxxx”作为我真正的 GitHub 用户名,然后是正确的 ACCESS_TOKEN。
go get github.com/private/repo 但是,我总是收到以下错误:
go: downloading github.com/xxxxxxxx/yyyyyyyyy-go-sdk v0.0.0-20200307154628-cbcb73911013
go get github.com/xxxxxxxx/yyyyyyyyy-go-sdk: github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: verifying module: github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: reading https://sum.golang.org/lookup/github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: 410 Gone
server response:
not found: github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/5eca4f397ed3a418f58ee864965ed24936e21268780304d6941f5b3983d31ad1: exit status 128:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下方法:
GONOSUMDB=github.com/myusername 去获取 github.com/xxxxxx/yyy...
根据 StackOverflow 上类似问题的一些答案,我尝试在 repo-url 后添加“.git”。但这根本行不通。
这可能是什么,我该如何解决?
版本:
? git --version
git version 2.25.0
hub version 2.14.2
Run Code Online (Sandbox Code Playgroud)
? 转到版本 1.14
iti*_*nce 30
你基本上一切都做对了,只是忘记了另一个重要步骤。
您需要告诉 Go 不要检查校验和,因为您是在自己的私有存储库上操作:
go env -w GOPRIVATE=github.com/mycompany/*
Run Code Online (Sandbox Code Playgroud)
替换mycompany为您在 github 上的用户名或您公司的名称,go get很可能会按预期工作。
小智 18
我有一个可能有帮助的解决方案。该问题发生在Golang 1.13以上版本。当我们在项目中使用私有模块时会发生这种情况。由于 Go Get 命令运行,golang 将执行代理校验和。因此,另一种选择是您需要GOPRIVATE在您的环境中添加环境。
export GOPRIVATE="github.com/private/repo"
Run Code Online (Sandbox Code Playgroud)
或者如果它不起作用,请尝试添加GONOPROXY环境。
export GONOPROXY="github.com/private/repo"
Run Code Online (Sandbox Code Playgroud)