如此,用dep获取私有库
介绍
dep是一个依赖管理工具。它需要 1.9 或更新的Golang版本才能编译
指南和参考资料,请参阅文档
获取私有库
我们常用的git方式有两种,第一种是通过ssh,第二种是https
本文中我们以gitlab.com为案例,创建一个private的私有仓库
通过ssh方式
首先我们需要在本机上生成ssh-key,若没有生成过可右拐 传送门
得到需要使用的ssh-key后,我们打开我们的gitlab.com,复制粘贴入我们的Settings -> SSH Keys中
添加成功后,我们直接在Gopkg.toml里配置好我们的参数
[[constraint]]
branch = "master"
name = "gitlab.com/eddycjy/test"
source = "git@gitlab.com:EDDYCJY/test.git"
在拉取资源前,要注意假设你是第一次用该ssh-key拉取,需要先手动用git clone拉取一遍,同意ECDSA key fingerprint:
$ git clone git@gitlab.com:EDDYCJY/test.git
Cloning into 'test'...
The authenticity of host 'gitlab.com (52.167.219.168)' can't be established.
ECDSA key fingerprint is xxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
...
接下来,我们在项目下直接执行dep ensure就可以拉取下来了!
问题
-
假设你是第一次,又没有执行上面那一步(
ECDSA key fingerprint),会一直卡住 -
正确的反馈应当是执行完命令后没有错误,但如果出现该错误提示,那说明该存储仓库没有被纳入
dep中(例:gitee)
$ dep ensure
The following issues were found in Gopkg.toml:
unable to deduce repository and source type for "xxxx": unable to read metadata: go-import metadata not found
ProjectRoot name validation failed
通过https方式
我们直接在Gopkg.toml里配置好我们的参数
[[constraint]]
branch = "master"
name = "gitlab.com/eddycjy/test"
source = "https://{username}:{password}@gitlab.com"
主要是修改source的配置项,username填写在gitlab的用户名,password为密码
最后回到项目下执行dep ensure拉取资源就可以了
最后
dep目前还是官方试验阶段,还可能存在变数,多加注意
热门评论
-
qq_唯一世_22018-12-29 0
查看全部评论unable to read metadata: unable to fetch raw metadata: failed HTTP request to URL "http://golang.org/x/crypto/acme/autocert?go-get=1"
报这个错怎么办?