用dep代替 go get 來擷取私人庫

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

dep 代替 go get 來擷取私人庫

(金慶的專欄 2017.11)

go get 功能比較弱,無法擷取分支,標籤,特定版本,fork, 而 dep 可以做到。dep 還可以擷取私人庫。

用 gitee.com 私人庫作測試。建立 gogettest 庫。

可用:

go get -u gitee.com/jinq0123/gogettest

如果改為私人庫則失敗:

λ go get -v gitee.com/jinq0123/gogettestFetching https://gitee.com/jinq0123/gogettest?go-get=1Parsing meta tags from https://gitee.com/jinq0123/gogettest?go-get=1 (status code 403)package gitee.com/jinq0123/gogettest: unrecognized import path "gitee.com/jinq0123/gogettest" (parse https://gitee.com/jinq0123/gogettest?go-get=1: no go-import meta tags ())

利用 dep 工具取私人庫

https://github.com/golang/dep

安裝dep

go get -u github.com/golang/dep/cmd/dep

初始化

在項目目錄下運行:

dep init

產生 Gopkg.tomlGopkg.lock

添加強制(constraint)

在 Gopkg.toml 中添加:

[[constraint]]  branch = "master"  name = "gitee.com/jinq012345/gogettest"  source = "https://gitee.com/jinq0123/gogettest.git"

source 強制使用 https 來擷取 gotgettest 庫。

注意庫名改成了 jinq012345, 這樣匯入:
imort "gitee.com/jinq012345/gogettest"

name和source的設定可支援從 fork 庫擷取。

擷取gogettest

dep ensure

會彈出 https 的登入使用者名稱和密碼輸入框。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.