git - 从私有(private)存储库获取依赖项的正确方法

标签 git go bitbucket go-modules go-get

我在 bitbucket 上有私有(private) http://localhost:7990 仓库👉🏻 克隆链接 http://localhost:7990/scm/gom/bar.gitgo.mod 看起来像:

module mod.org/bar

go 1.13
远程存储库中可用的引用:
git ls-remote  http://localhost:7990/scm/gom/bar.git 

From http://localhost:7990/scm/gom/bar.git
d456de4f12785b26ac27ba08cffb76687d1287c8        HEAD
d456de4f12785b26ac27ba08cffb76687d1287c8        refs/heads/master
f948bd47a22c5fb9abed5bff468a10fc24f67483        refs/tags/v1.0.0
我将 .gitconfig 更改为
[url "http://localhost:7990/scm/gom"]
      insteadOf = https://mod.org
并试图通过 name 获取模块,得到 no such host 错误:
go get -v mod.org/bar

go get lmod.org/bar: unrecognized import path "lmod.org/bar" (https fetch: Get https://lmod.org/bar?go-get=1: dial tcp: lookup lmod.org: no such host)
当我添加扩展 .git
go get -v mod.org/bar.git 

go: finding lmod.org/bar.git v1.0.0
go: downloading lmod.org/bar.git v1.0.0
verifying lmod.org/bar.git@v1.0.0: lmod.org/bar.git@v1.0.0: reading https://sum.golang.org/lookup/lmod.org/bar.git@v1.0.0: 410 Gone
go 下载带有标签 v1.0.0GOPATH = /Users/user/go" 的版本:
$GOPATH
└── go
     └── pkg
         └── mod
             └── cache
                 └── download
                     └── mod.org
                         └── bar.git
                             └── @v
                                 ├── v1.0.0.info
                                 ├── v1.0.0.lock
                                 └── v1.0.0.zip.tmp882433775
,但我仍然不能在其他 go-project 中使用一个作为依赖项。

最佳答案

https://mod.org/bar 的服务器需要退货go-import遵循 https://golang.org/cmd/go/#hdr-Remote_import_paths 中描述的协议(protocol)的元数据.

存在几个开源实现,例如:

  • rsc.io/go-import-redirector
  • github.com/GoogleCloudPlatform/govanityurls

  • 您可以将 HTTPS 服务器和底层存储库的凭据(或访问 token )存储在 .netrc 中。文件,并使用 GOPRIVATE 告诉go的环境变量命令不要在公共(public)代理中查找您的私有(private)仓库。

    关于git - 从私有(private)存储库获取依赖项的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60585302/

    相关文章:

    go - gccgo,AIX:编译的.o文件不包含.go_export节

    ios - 如何从 Azure Pipeline 在 Bitbucket 中更新构建状态?

    security - GIT 支持基于分支的用户授权——最佳实践还是工具?

    Git 服务器拒绝访问

    git - 如何使用带有模块的私有(private) go 包

    git - 将 repo 从 bitbucket 转移到 github 失败

    git - 对于 Git 存储库,GitHub 相对于 Bitbucket 的优势

    git - 此错误消息意味着什么 : fatal: unable to access 'https:URL' : Peer's Certificate issuer is not recognized?

    go - 如何检查文件是否包含字符串?

    go - 如何使用 mgo 从嵌套接口(interface)的 mongo 解码 bson?