Go Commands
https://golang.org/cmd/
Table of Contents
go get
go install
go test
go build
vsgo install
- Can I omit
[packages]
ingo action [packages]
? gofmt
vsgoimports
- What do three dots(
./...
) mean?
go get
reference
- Get downloads the packages named by the import paths, along with their dependencies.
- It then installs the named packages, like
go install
.
# If you don't specify any packages, it implies the current package('.'),
# which results in getting all packages that the current package depends
go get -t
# Or, just specify a package.
go get -u -v golang.org/x/tools/cmd/goimports
-t
Also downloads the packages required to build the tests for the specified packages.
-u
- 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. -v
Enables verbose progress and debug output.
go install
reference
-i
- Installs the dependencies of the named packages as well.
go test
reference
go test [build/test flags] [packages] [build/test flags & test binary flags]
To browse flags, run go test -help
-v
- verbose
There are two modes:
- Run without
[packages]
(justgo test
orgo test -v
) - Run tests on the package of the current directory.
- Caching is disabled
- Prints a somewhat detailed test result.
- Run with
[packages]
- Unless it changes, it caches the result and prints the last output if exists.
- If passed, just Prints
ok
.
go build
vs go install
discussion
go build
- The resulting executable named after the first source file (
go build ed.go rx.go
writesed
ored.exe
)
- The resulting executable named after the first source file (
go install
- It does a little more than
go build
. - It moves the executable file to
$GOPATH/bin
and cache all non-main packages which imported to$GOPATH/pkg
- The cache will be use in the next compile if it not changed yet.
- It does a little more than
Can I omit [packages]
in go action [packages]
? discussion
- If no import paths are given, the action applies to the package in the current directory.
gofmt
vs goimports
discussion
goimports
does everything thatgofmt
do.- It tidies up
import
statements
What do three dots(./...
) mean? discussion
An import path is a pattern if it includes one or more "
...
" wildcards, each of which can match any string, including the empty string and strings containing slashes. Such a pattern expands toall package directories
found in theGOPATH
trees with names matching the patterns. As a special case,x/...
matchesx
as well as x's subdirectories.