2.2 如此,用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.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目前還是官方試驗階段,還可能存在變數,多加註意