In Go 1.6, the vendor feature allows for dependency management without using external package managers. However, importing packages using this new feature can be challenging for first-time users. Here's a step-by-step solution to the problem encountered in the original question.
The provided project structure seems correct, with the vendor directory containing the dependency package github.com/zenazn/goji. The value of GOPATH also appears to be set correctly.
The issue lies in the build commands. To build the program with the dependencies in the vendor directory, use the following commands:
<code class="bash">$GOPATH=`pwd` go install main.go</code>
This command instructs go to use the current directory as the GOPATH, ensuring that it can find the vendor directory and the main.go program.
Alternatively, you can set your GOPATH using an environment variable to include the directory where your project is located. For example:
<code class="bash">export GOPATH=~/my-go-projects:~/my-vendor-projects</code>
Once the GOPATH is set correctly, you can use the following command to build the program:
<code class="bash">go install main.go</code>
After executing the build command, the resulting binary will be placed in $GOPATH/bin/main, and you'll be able to run the program as usual.
The above is the detailed content of How Do I Import Packages Using Vendor in Go 1.6?. For more information, please follow other related articles on the PHP Chinese website!