首頁  >  文章  >  後端開發  >  有,總比沒有好:Go依賴管理工具dep

有,總比沒有好:Go依賴管理工具dep

Go语言进阶学习
Go语言进阶学习轉載
2023-07-21 13:13:461329瀏覽
<br>

有,總比沒有好:Go依賴管理工具dep

    「 讀這篇文章大概需要3.4分鐘」

#    早期的Golang被許多開發者所詬病的一個問題就是依賴包的管理。 Golang 1.5 release版本的發布之前,只能透過設定多個GOPATH的方式來解決這個問題,例如:我兩個工程都依賴了Beego,但A工程依賴的是<span style="color: rgb(217, 72, 99);">Beego1.1</span>,B工程依賴的是<span style="color: rgb(217, 72, 99);">#Beego1.7</span>##,我必須設定兩個GOPATH來區分,在切換工程的時候GOPATH也得切換,無比痛苦。終於終於在Golang 1.5 release 開始支援除了GOROOT和GOPATH之外的依賴查詢,那就是vender<span style="color: rgb(217, 72, 99);"></span>所以很多大佬開始造輪子,造得比較好的應該是dep<span style="color: rgb(217, 72, 99);"></span>#和##glide <span style="color: rgb(217, 72, 99);"></span>。 主角出場

    今天的主角是

dep,Golang的官方依賴工具,用來管理和下載工程依賴的工具,以下是官方的介紹

dep is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. dep is safe for production use.

安裝

  • #MacOS

     ##brew install dep <span style="color: rgb(217, 72, 99);"></span>

  • Linux
  • #curl https://raw.githubusercontent.com/golang/dep/master /install.sh | sh<span style="color: rgb(217, 72, 99);"></span>

  • #Windows
  •  

    go get -u github.com /golang/dep/cmd/depWindows得自己編譯,並且確認把

    $GOPATH/bin# 加入環境變數$PATH<span style="color: rgb(217, 72, 99);">下</span>

驗證

    在命令列輸入<span style="color: rgb(217, 72, 99);">#dep</span>並回車,會出現以下提示的話,說明已經安裝成功了。

有,總比沒有好:Go依賴管理工具dep

<br>

功能介紹

1.dep init<br>#    備份目前的<span style="color: rgb(199, 37, 78);">vender</span> ,建立<span style="color: rgb(61, 69, 76);">vender</span>目錄並下載專案中的所有依賴包,產生 <span style="color: rgb(199, 37, 78);">Gopkg.lock</span><span style="color: rgb(199, 37, 78);">#Gopkg.toml</span>##以下是兩個文件的作用說明,簡單講Gopkg.toml<span style="color: rgb(199, 37, 78);"></span>#是清單文件, Gopkg.lock是校驗描述檔。盡量不要修改,避免造成兩個檔案不同步的錯誤。

A manifest - a file describing the current project's dependency requirements. In dep, this is the Gopkg.toml file.

A lock - a file containing a transitively-complete, reproducible, reproducible description of the dependency graph. In dep, this is the Gopkg.lock file.<br>

有,總比沒有好:Go依賴管理工具dep

<br>

2.dep status

    用來查看專案依賴的詳細資訊和狀態,非常清楚。  

有,總比沒有好:Go依賴管理工具dep

3.dep ensure<br>    嘗試確保所有的依賴函式庫都已安裝,如果沒有即下載,相當於對依賴函式庫做增量更新。

<br>

#4.dep ensure add github.com/RoaringBitmap/roaring@^1.0.1

    下載新增新的依賴函式庫,並增量更新清單檔案和校驗描述檔。 github.com/RoaringBitmap/roaring 是依賴函式庫的套件名, 1.0.1是函式庫的版本號碼。

本機快取

<span style="color: rgb(61, 69, 76);font-size: 16px;">    當然</span><span style="font-size: 16px;color: rgb(199, 37, 78);"><strong>dep</strong></span><span style="color: rgb(61, 69, 76);font-size: 16px;">不會每次都去下載,其工作原理和Mevan一樣,會優先在本地倉庫搜索,本地倉庫未找到即在網絡上下載,並添加到本地倉庫。 </span>

$GOPATH/pkg/dep/sources

以上是有,總比沒有好:Go依賴管理工具dep的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:Go语言进阶学习。如有侵權,請聯絡admin@php.cn刪除