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