Library

vendor/ 與第 3 方依賴項的子目錄關係

  • July 20, 2017

-go-ethereum客戶端目錄中,我執行了find . -name \*.md -print查找README.md文件的命令。輸出如下:

   ./.github/CONTRIBUTING.md
   ./.github/ISSUE_TEMPLATE.md
   ./build/ci-notes.md
   ./contracts/ens/README.md
   ./crypto/secp256k1/libsecp256k1/README.md
   ./log/README.md
   ./log/README_ETHEREUM.md
   ./README.md
   ./swarm/dev/README.md
   ./vendor/bazil.org/fuse/README.md
   ./vendor/github.com/aristanetworks/goarista/README.md
   ./vendor/github.com/Azure/azure-sdk-for-go/CHANGELOG.md
   ./vendor/github.com/Azure/azure-sdk-for-go/README.md
   ./vendor/github.com/Azure/azure-storage-go/README.md
   ./vendor/github.com/btcsuite/btcd/btcec/README.md
   ./vendor/github.com/cespare/cp/README.md
   ./vendor/github.com/davecgh/go-spew/README.md
   ./vendor/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md
   ./vendor/github.com/dgrijalva/jwt-go/README.md
   ./vendor/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md
   ./vendor/github.com/docker/docker/pkg/reexec/README.md
   ./vendor/github.com/edsrzf/mmap-go/README.md
   ./vendor/github.com/fatih/color/LICENSE.md
   ./vendor/github.com/fatih/color/README.md
   ./vendor/github.com/gizak/termui/README.md
   ./vendor/github.com/go-stack/stack/LICENSE.md
   ./vendor/github.com/go-stack/stack/README.md
   ./vendor/github.com/hashicorp/golang-lru/README.md
   ./vendor/github.com/huin/goupnp/README.md
   ./vendor/github.com/jackpal/go-nat-pmp/README.md
   ./vendor/github.com/karalabe/hid/LICENSE.md
   ./vendor/github.com/karalabe/hid/README.md
   ./vendor/github.com/maruel/panicparse/README.md
   ./vendor/github.com/mattn/go-colorable/README.md
   ./vendor/github.com/mattn/go-isatty/README.md
   ./vendor/github.com/mitchellh/go-wordwrap/LICENSE.md
   ./vendor/github.com/mitchellh/go-wordwrap/README.md
   ./vendor/github.com/naoina/go-stringutil/README.md
   ./vendor/github.com/naoina/toml/README.md
   ./vendor/github.com/nsf/termbox-go/README.md
   ./vendor/github.com/olekukonko/tablewriter/LICENCE.md
   ./vendor/github.com/olekukonko/tablewriter/README.md
   ./vendor/github.com/pborman/uuid/CONTRIBUTING.md
   ./vendor/github.com/pborman/uuid/README.md
   ./vendor/github.com/peterh/liner/README.md
   ./vendor/github.com/rcrowley/go-metrics/memory.md
   ./vendor/github.com/rcrowley/go-metrics/README.md
   ./vendor/github.com/rjeczalik/notify/README.md
   ./vendor/github.com/rs/cors/README.md
   ./vendor/github.com/rs/xhandler/README.md
   ./vendor/github.com/syndtr/goleveldb/README.md
   ./vendor/golang.org/x/crypto/CONTRIBUTING.md
   ./vendor/golang.org/x/net/CONTRIBUTING.md
   ./vendor/golang.org/x/sys/CONTRIBUTING.md
   ./vendor/golang.org/x/text/CONTRIBUTING.md
   ./vendor/golang.org/x/tools/CONTRIBUTING.md
   ./vendor/gopkg.in/check.v1/README.md
   ./vendor/gopkg.in/fatih/set.v0/LICENSE.md
   ./vendor/gopkg.in/fatih/set.v0/README.md
   ./vendor/gopkg.in/karalabe/cookiejar.v2/README.md
   ./vendor/gopkg.in/natefinch/npipe.v2/README.md
   ./vendor/gopkg.in/sourcemap.v1/README.md
   ./vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md
   ./vendor/gopkg.in/urfave/cli.v1/README.md

基於此,看起來所有“第 3 方”依賴項都位於vendor/目錄中。是這樣嗎?為什麼這個目錄被稱為vendor

基於此,看起來所有“第 3 方”依賴項都位於 vendor/ 目錄中。是這樣嗎?

是,對的。

為什麼這個目錄被稱為供應商?

這是 Go 中的約定,在 golang 1.6 中引入(在 1.5 中進行實驗)。

請參閱官方文件,此處:https ://golang.org/cmd/go/#hdr-Vendor_Directories

簡而言之:

Go 1.6 支持使用外部依賴項的本地副本來滿足這些依賴項的導入,通常稱為供應商。

名為“vendor”的目錄下的程式碼只能通過以“vendor”的父級為根的目錄樹中的程式碼導入,並且只能使用省略前綴直到並包括 vendor 元素的導入路徑。

引用自:https://ethereum.stackexchange.com/questions/21689