Go Tools
Maximilian Wurzer
Advisory IT Architect, IBM Deutschland
Maximilian Wurzer
Advisory IT Architect, IBM Deutschland
Compiler, package-manager, formatter, linter, ... all in a single tool:
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
2
go run
: Compile and run a program ad-hoc
go run hello.go
go build
: Compile or cross-compile program
go build hello.go
GOOS=windows GOARCH=amd64 go build hello.go
go test
: Run tests
go test ./...
go get
: Download a dependency of a module and install them
go get -u github.com/google/uuid
go doc
: Get the docs for a method
go doc http.ListenAndServe
package http // import "net/http"
func ListenAndServe(addr string, handler Handler) error
ListenAndServe listens on the TCP network address addr and then calls Serve
with handler to handle requests on incoming connections. Accepted
connections are configured to enable TCP keep-alives.
The handler is typically nil, in which case the DefaultServeMux is used.
ListenAndServe always returns a non-nil error.
go mod
: Interact with modules
go mod init
go mod vendor
import 'gitlab.com/my/project'
go.mod
file:module example.com/my/thing
go 1.12
require example.com/other/thing v1.0.2
require example.com/new/thing/v2 v2.3.4
exclude example.com/old/thing v1.2.3
replace example.com/bad/thing v1.4.5 => example.com/good/thing v1.4.5
7
Maximilian Wurzer
Advisory IT Architect, IBM Deutschland