This is a creation in Article, where the information may have evolved or changed.
Http://www.tuicool.com/articles/NjMzIbJ
In addition to the extensive use of Python in our projects, we also use Golang to build efficient basic operational services. In using the Golang process, we found that the lack of dependent library version of the Golang program is a very big problem: some dependencies after a commit after the API changes, if not to modify the code is difficult to be compatible, but the developer is very likely because of the time of participation, resulting in the execution go getcommand gets a different version, resulting in a compile-through problem on different computers. Also, in multiple programs, if you use a different version of commit, you may cause different problems during program compilation.
Before we solved this problem there are two scenarios, one is to disassemble the go get execution of the command, first create the corresponding dependent directory, use the git command to switch to the specified commit, and then execute the go install command. Another easy way to do this is to use the GODEP tool, which does not introduce too much, you can refer to the document or search the Chinese course.
After the Golang1.5, go providesGO15VENDOREXPERIMENTAn environment variable that adjusts the application path search at go build to当前项目目录/vendorDirectory mode. In this form, we can implement similargodepThe way the project relies on management. But at least in the process of compiling, there is no need to deploy agodepTools.
Before using, you need to install an auxiliary tool (if Golang self-change one): go get-u-v github.com/kardianos/govendor .
below, we use an example to illustrate. First there is a name of vendorproj project. If there is only one file:
package mainimport (" Github.com/yeeuu/echoic " ) Func Main () {e: = echoic. New () e.setdebug (true ) E.run (" 127.0.0.1:4321 ")}
Execute the command to generate the Vendor folder:
$ govendor init$ lsmain.go vendor$ CD vendor/$ Lsvendor.json
this vendor.json will resemble GODEP the functionality of the description file version in the tool. Next, you need to execute a command to include the file that the current app must have in
$ govendor add +external
If you need to update or remove, refer to the tool's specific documentation update or remove commands. This will move the required compilation files into the vendor directory (note: The dependencies required for testing are not included, and the test files that depend on the project are not included).
$ Lsgithub.com golang.org Vendor.json$ Cat vendor.json{"comment": "","Ignore": "Test","Package":[ {"Path": "Github.com/yeeuu/echoic","revision": "a7d6994f92e2dc60cff071ae38b204fbd4bd2a3f","Revisiontime": "2015-12-18t11:14:29+08:00"}, {"Path": "Golang.org/x/net/context","revision": "1d9fd3b8333e891c0e7353e1adcfe8a612573033","Revisiontime": "2015-11-13t15:40:13-08:00"} ]}$ CD Github.com/yeeuu/echoic$ LsLICENSEContext.go Group.go Router.goREADME. MD Echoic.go Response.go
by setting the environment variable go15vendorexperiment=1 build files using the Vendor folder. can choose export go15vendorexperiment=1 or simply go15vendorexperiment=1 go Build perform compilation.
In this way, you can ensure that a program can implement a pattern similar to virtualenv in Python, and that different programs use different versions to rely on.