GODEP Support Go 1.5 vendor

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go 1.5 vendor/Experimental features out of the market, go third-party package dependencies and management tools are obviously not compatible with it, in addition to modifying the code, there is no other way. GODEP, the largest market share, has taken the lead, and the latest version (go get GITHUB.COM/TOOLS/GODEP) has initially supported the experimental feature, which is to use vendor when Go15vendorexperiment=1 The directory (not the Godeps directory) holds a copy of the third-party package, and GODEP go build no longer rewrite Gopath can be implemented using vendor under the third-party package. Let's use examples to verify GODEP's support for vendor.

First, upgrade GODEP to the latest version

If you want to use Go 1.5 vendor, then GODEP to upgrade (go get-u github.com/tools/godep;go build github.com/tools/godep) to the current version of "Commit D8799F112F6C8DFE1E56142831BC3BB5C8796A0E ". The latest version is compatible with the old version of the feature, while providing support for Go 1.5 vendor, the switch between the two is the environment variable: go15vendorexperiment.

When Go15vendorexperiment is not set, GODEP follows the previous way; when go15vendorexperiment = 1 o'clock, GODEP will replace vendor directories with Godeps to hold third-party packages, while go Save will not be able to use the-r command-line option (the-r option for overriding the import path in source code):

$ GODEP Save-r
Godep:flag-r is incompatible with the vendoring experiment

Second, Example

Here is a godep example (Go 1.5 beta3), the directory structure of the example is as follows:

$ (Gopath)/src/tonybai.com/
├──app
│└──main.go
└──foolib
└──foolib.go

Foolib.go
Package Foo

Import "FMT"

Func Hello () {
Fmt. Println ("Hello from Foolib")
}

Main.go
Package Main

Import "Tonybai.com/foolib"

Func Main () {
Foo. Hello ()
}

If the go15vendorexperiment is not set, the various commands of GODEP will be executed in the same way as before.

$ GODEP Save
$ GODEP Go Build

$ (Gopath)/src/tonybai.com/
├──godeps
│├──godeps.json
│├──readme
│└──_workspace
│└──src
│└──tonybai.com
│└──foolib
│└──foolib.go
├──app*
└──main.go

$./app
Hello from Foolib

GODEP The third-party package under GODEPS/_WORKSPACE/SRC. GODEP go build rewrite Gopath for the purpose of building using the third-party package under _workspace.

If go15vendorexperiment = 1, then GODEP executes the various commands in the new way:
$ GODEP Save
$ GODEP Go Build

$ (Gopath)/src/tonybai.com/
├──godeps
│├──godeps.json
│└──readme
├──app*
├──main.go
└──vendor
└──tonybai.com
└──foolib
└──foolib.go

You can see that GODEP set up a vendor directory to hold third-party packages, godeps directories remain, but only store Godeps.json to hold meta-information about third-party packages:
Godeps.json
{
"Importpath": "Tonybai.com/app",
"Goversion": "Go1.5beta3",
"Deps": [
{
"Importpath": "Tonybai.com/foolib",
"Rev": "7f2f94dc589ba9e053ef13b3b01fa327c27bf161"
}
]
}

Third, migration

Since the two working modes before and after GODEP are not compatible, a large amount of stock is used GODEP repo, if you want to use Go 1.5 vendor, then you need to do some migration after upgrading to go 1.5. GODEP does not provide automatic migration tools and is currently only manually migrated, GODEP the Manual Migration Command steps on the GitHub home page:

$ unset go15vendorexperiment
$ GODEP Restore

If you have previously used GODEP Save-r, then this line of command will automatically undo rewritten import.
$ GODEP save./...

$ RM-RF Godeps
$ Export Go15vendorexperiment=1
$ GODEP save./...
# you should see your godeps/_workspace/src files ' moved ' to vendor/.

Bigwhite. All rights reserved.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.