Go Commands
https://golang.org/cmd/
Table of Contents
go getgo installgo testgo buildvsgo install- Can I omit
[packages]ingo action [packages]? gofmtvsgoimports- 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-tAlso 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,
getuses the network to check out missing packages but does not use it to look for updates to existing packages. -vEnables 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 testorgo 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.gowritesedored.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/binand 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
goimportsdoes everything thatgofmtdo.- It tidies up
importstatements
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 directoriesfound in theGOPATHtrees with names matching the patterns. As a special case,x/...matchesxas well as x's subdirectories.