這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
如此,用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 ensureThe following issues were found in Gopkg.toml:unable to deduce repository and source type for "xxxx": unable to read metadata: go-import metadata not foundProjectRoot 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目前還是官方實驗階段,還可能存在變數
請務必以sf上的原文為準,如果dep新版本有變動,會隨著修改