- 如此,用dep获取私有库
- 介绍
- 获取私有库
- 通过
ssh方式- 问题
- 通过
- 最后
如此,用dep获取私有库
介绍
dep是一个依赖管理工具。它需要1.9或更新的Golang版本才能编译
dep已经能够在生产环节安全使用,但还在官方的试验阶段,也就是还不在go tool中。但我想是迟早的事 :=)
指南和参考资料,请参阅文档
获取私有库
我们常用的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.gitCloning 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 = “@gitlab.com"">https://{username}:{password}@gitlab.com“
```
主要是修改source的配置项,username填写在gitlab的用户名,password为密码
最后回到项目下执行dep ensure拉取资源就可以了
最后
dep目前还是官方试验阶段,还可能存在变数,多加注意
