登录
首页 >  Golang >  Go问答

使用私有存储库进行构建

来源:stackoverflow

时间:2024-04-02 15:27:36 397浏览 收藏

今天golang学习网给大家带来了《使用私有存储库进行构建》,其中涉及到的知识点包括等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~

问题内容

我正在尝试构建一个使用私有 git 存储库的 go 应用程序。我的 github 帐户有一个 ssh 密钥,并且我的 .gitconfig 文件中有以下内容:

[url "https://username:[email protected]"]
    insteadof = https://github.com
[url "ssh://[email protected]/"]
    insteadof = https://github.com/

当我执行 go test 或 go build 时,系统会要求我输入密码。然后我得到回复:

go: found github.com/x/businesses in github.com/x/businesses v0.0.0-yy
go: cmd/main/cmd imports
  github.com/x/businesses: github.com/x/[email protected]/go.mod: 
  verifying module: github.com/x/[email protected]/go.mod: 
  reading https://sum.golang.org/lookup/github.com/xx/[email protected]: 410 Gone
server response:
  not found: github.com/x/[email protected]: 
  invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* 
  in tmp/gopath/pkg/mod/cache/vcs/zz: 
    exit status 128:
    fatal: could not read Username for 'https://github.com': terminal prompts disabled

我尝试删除 .gitconfig 中的 top 而不是出于其他原因,只是为了尝试一些东西。


解决方案


你的 git 配置应该类似于

[url "[email protected]:"] insteadof = https://github.com/

或与您拥有的类似。

然后你可以通过告诉 go 你使用这样的私人仓库来获取你的软件包:

GOPRIVATE="github.com/your_username_or_org" go get github.com/name_or_org/repo_name

此外,我通常不会在 ssh 密钥上添加密码,因为每次都输入密码有点烦人,但当然,像评论中有人指出的那样添加它会更安全。

今天关于《使用私有存储库进行构建》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>