Go Commands

https://golang.org/cmd/

Table of Contents

go get reference

# 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] (just go test or go 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 writes ed or ed.exe)
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.

Can I omit [packages] in go action [packages]? discussion

gofmt vs goimports discussion

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 to all package directories found in the GOPATH trees with names matching the patterns. As a special case, x/... matches x as well as x's subdirectories.