如此,用dep獲取私有庫

如此,用dep獲取私有庫

介紹

dep是一個依賴管理工具。它須要1.9或更新的Golang版本才能編譯git

dep已經可以在生產環節安全使用,但還在官方的試驗階段,也就是還不在go tool中。但我想是早晚的事 :=)github

指南和參考資料,請參閱文檔golang

獲取私有庫

咱們經常使用的git方式有兩種,第一種是經過ssh,第二種是httpssegmentfault

本文中咱們以gitlab.com爲案例,建立一個private的私有倉庫安全

經過ssh方式

首先咱們須要在本機上生成ssh-key,若沒有生成過可右拐傳送門ssh

獲得須要使用的ssh-key後,咱們打開咱們的gitlab.com,複製粘貼入咱們的Settings -> SSH Keys工具

圖片描述

添加成功後,咱們直接在Gopkg.toml裏配置好咱們的參數gitlab

[[constraint]]
  branch = "master"
  name = "gitlab.com/eddycjy/test"
  source = "git@gitlab.com:EDDYCJY/test.git"

在拉取資源前,要注意假設你是第一次用該ssh-key拉取,須要先手動用git clone拉取一遍,贊成ECDSA key fingerprintspa

$ 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就能夠拉取下來了!code

問題

  1. 假設你是第一次,又沒有執行上面那一步(ECDSA key fingerprint),會一直卡住
  2. 正確的反饋應當是執行完命令後沒有錯誤,但若是出現該錯誤提示,那說明該存儲倉庫沒有被歸入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目前仍是官方試驗階段,還可能存在變數

請務必以sf上的原文爲準,若是dep新版本有變更,會隨着修改

相關文章
相關標籤/搜索