Author: ReganYue
Source: Hang Seng LIGHT Cloud Community
1. Use go get
The GO command, GO Get, allows us to quickly and easily download or update the GO language package and its dependencies from the network, and compile and install them.
- Enter the command line mode first
go --help
, you can view the following information.
Go is a tool for managing Go source code.
Usage:
go <command> [arguments]
The commands are:
bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
fix update packages to use new APIs
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get add dependencies to current module and install them
install compile and install packages and dependencies
list list packages or modules
mod module maintenance
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet report likely mistakes in packages
Use "go help <command>" for more information about a command.
Additional help topics:
buildconstraint build constraints
buildmode build modes
c calling between Go and C
cache build and test caching
environment environment variables
filetype file types
go.mod the go.mod file
gopath GOPATH environment variable
gopath-get legacy GOPATH go get
goproxy module proxy protocol
importpath import path syntax
modules modules, module versions, and more
module-get module-aware go get
module-auth module authentication using go.sum
module-private module configuration for non-public modules
packages package lists and patterns
testflag testing flags
testfunc testing functions
Use "go help <topic>" for more information about that topic.
Copy the code
Get add dependencies to current module and install them
That’s what we’re going to use today.
Then check its help message: Go get –help
usage: go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]
Run 'go help get' for details.
Copy the code
Find the library we want to get.
Copy link https://github.com/go-sql-driver/mysql
Use go get github.com/go-sql-driver/mysql
Result error:
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/go-sql-driver/mysql: exec: "git": executable file not found in %PATH%
Copy the code
Git is installed, and the blogger has Git installed, but it needs to be configured.
Add Git’s bin directory to the system variable PATH.
Then run go get github.com/go-sql-driver/mysql
Now it works.
This github.com/go-sql-driver/mysql is called the remote import path, but actually go get is called the remote dynamic import go package. All go Get does is take a code package from a distributed version control repository and compile and install it.
Warehouse, | VCS | VCS | VCS |
---|---|---|---|
BitBucket | Mercurial | Git | |
GitHub | Git | ||
Google Code Project Hosting | Git | Mercurial | Subversion |
Launchpad | Bazaar |
Typically, the first element in the package’s remote import path is the main domain of the site where the code is hosted. During static analysis, the go Get command matches the remote import path of the code package with the primary domain name of the preset code hosting site. If the match is successful, the normal return value or error message is returned after an initial check of the code package’s remote import path. If the match is unsuccessful, the code package remote import path is analyzed dynamically.
Download the GO library directly
Download the Go library on Github or elsewhere.
Then look at GOPATH in the system variable.
Then open GOPATH’s SRC directory
Copy the file in.
And then you get it.
3. Parameter introduction
usage: go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]
Run 'go help get' for details.
Copy the code
Then we can look at the description of parameters in Go Help Get.
The -d flag instructs get to stop after downloading the packages; that is,
it instructs get not to install the packages.
The -f flag, valid only when -u is set, forces get -u not to verify that
each package has been checked out from the source control repository
implied by its import path. This can be useful if the source is a local fork
of the original.
The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.
The -insecure flag permits fetching from repositories and resolving
custom domains using insecure schemes such as HTTP. Use with caution.
The -t flag instructs get to also download the packages required to build
the tests for the specified packages.
The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.
The -v flag enables verbose progress and debug output.
Copy the code
To put it simply:
- -d Stop work after downloading, do not install library
- The -f argument is only useful if the -u argument is used, forcing -u not to verify that each package imported has been fetched is useful for packages forked locally.
- -fix The -fix parameter indicates that the fix tool should be run before resolving dependencies or building code.
- -insecure This parameter allows the repository to be retrieved and parsed over a custom domain that is insecure (for example, HTTP).
- -t Allows the test package to be downloaded when the package is downloaded.
- The -u argument allows GET to use the network to update packages and their dependencies. By default, GET uses the network to check for missing packages, but does not use it to find updates to existing packages.
- -v Enables output of detailed progress and debugging information.