go - 无法通过 SSH 安装 go 模块(私有(private)嵌套存储库)

标签 go gitlab go-modules

重现步骤

  • 安装 Go 1.14
  • 在 Gitlab 中创建私有(private)组织
  • 在组织中创建私有(private)子组
  • 在子组
  • 中创建一个私有(private)存储库
  • 在本地克隆存储库
  • cd 到存储库
  • 初始化新的 go 模块 go mod init gitlab.com/myorganisation/mysubgroup/myrepository
  • 提交并推送
  • cd 到另一个启用模块的存储库
  • 运行go get gitlab.com/myorganisation/mysubgroup/myrepository

  • 出现错误:
    go get gitlab.com/myorganisation/mysubgroup/repo1: git ls-remote -q https://gitlab.com/myorganisation/mysubgroup.git in /Volumes/CS/go/pkg/mod/cache/vcs/a96c83d4d1395bc931a1a8ac402e8d8e494cc85efa9081cab02316963aa836ed: exit status 128:
            The project you were looking for could not be found.
            fatal: Could not read from remote repository.
            
            Please make sure you have the correct access rights
            and the repository exists.
    

    最佳答案

  • ~/.gitconfig:
  •     [url "git@gitlab.com:"]
            insteadOf = https://gitlab.com/
    
    1.设置环境:
        GONOPROXY="gitlab.com/mycorp/*"
        GONOSUMDB="gitlab.com/mycorp/*"
        GOPRIVATE="gitlab.com/mycorp/*"
    
  • 在 go.mod 文件中,将子组 repo 的路径从“gitlab.com/myorganisation/mysubgroup/myrepository”更改为“gitlab.com/myorganisation/mysubgroup/myrepository.git”。所有子组 repo 导入路径都相同。
  • 转到需要上述子组 repo 的先前存储库并调用“go get -insecure gitlab.com/myorganisation/mysubgroup/myrepository.git”

  • 之后 go.mod 必须更新,一切都会开始正常工作。

    关于go - 无法通过 SSH 安装 go 模块(私有(private)嵌套存储库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63932562/

    相关文章:

    go.mod 在修订时有 post-v0 模块路径 "git.example.com/owner/repo/v3"...?

    unit-testing - 您如何为连接到授权帐户的库编写测试?

    go - 以字符串开头的结构字段名称

    gitlab - 获取 extends 关键字以在本地 gitlabci 运行器中工作

    hyperlink - header 的 Markdown 链接

    go - 如何使用 Go 模块修复 Go build error "can' t load package"?

    http - Golang网拨用户:pass@ip:port gives: no such host

    Go:在二进制中嵌入静态文件

    docker - 为 gitlab ci 社区版启用 docker

    git - 去使用 ssh 而不是 https(不在 github 上)