Home > Backend Development > Golang > How Do I Import Packages Using Vendor in Go 1.6?

How Do I Import Packages Using Vendor in Go 1.6?

Susan Sarandon
Release: 2024-10-31 01:04:29
Original
303 people have browsed it

How Do I Import Packages Using Vendor in Go 1.6?

Importing Packages Using Vendor in Go 1.6

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>
Copy after login

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>
Copy after login

Once the GOPATH is set correctly, you can use the following command to build the program:

<code class="bash">go install main.go</code>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template