Go get prerequisites and steps for installing third-party packages

Source: Internet
Author: User


First, you need to find the URL of the third-party package, for example: Http://github.com/go-sql-driver/mysql
Divided into command line automatic installation and manual download and then install.

(Welcome to the Go language group: 218160862, there is practice in the group)


First, install the third-party class library through the go get github.com/go-sql-driver/mysql command
to enable the go get github.com/go-sql-driver/mysql command,
You must first set the path to the environment variable gopath, and install git for Windows!!! Otherwise the go get command does not work.


1. Set the GOPATH environment variable, and the path inside the Gopath variable cannot have a semicolon;
right-My Computer-Advanced system settings-environment variables, click "New" under System variables
Input: Line 1th: Gopath line 2nd: You specify the path, for example: D:\go\gopath (note that the end of the semicolon is removed)


2. Install git for Windows, http://git-for-windows.github.io/

3. You can then execute the go get github.com/go-sql-driver/mysql command to install a third-party package.
This command will extract the class library package source code, download it into your%gopath% path,
For example: D:\go\gopath\ src\github.com\go-sql-driver\mysql

The front is the Gopath path, followed by the class library, and it also executes go install XXX, generating a package path such as D:\go\gopath\pkg\xxxx.

4. Import the downloaded third-party package in your code
Import (
"Github.com/go-sql-driver/mysql"//Search for third-party class libraries from the path defined in environment variables:%gopath%
)


Second, manually install the third-party class library
If you use Go get github.com/go-sql-driver/mysql, you must first install the Git tool.
If you manually download the package, unzip it to the path inside the GOPATH/SRC, and then execute the Go install github.com/go-sql-driver/mysql the package,


The final import of the downloaded third-party package in the code is the same, but be aware of its path inside the go/pkg.

Import (
"Github.com/go-sql-driver/mysql"//Search for third-party class libraries from the path defined in environment variables:%gopath%
)

Go get prerequisites and steps for installing third-party packages

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.