Go

Go intro

Module based usage is assumed. A module is like a python virtualenv.

1
go help modules

GOPATH environment variable defaults to $HOME/go and is used to resolve import statements.

Initialize a module.

1
2
mkdir hello && cd hello
go mod init example.com/hello

Add module requirements and sums after creating the .go file.

1
go mod tidy

Run the code.

1
go run .

Remove a dependency on a module and downgrade modules that require it.

1
go get rsc.io/quote@none

List modules (-m) that are dependencies of your current module, with the latest version available for each (-u).

1
go list -m -u all

Replace module remote path with local filesystem path. Modules are generally intended to be published in a decentralized manner.

1
go mod edit -replace example.com/greetings=../greetings

Manage dev tools written in Go.

1
go get -tool golang.org/x/tools/cmd/stringer

List tools

1
go tool

Compile the executables, including dependencies.

1
2
go build
go install # compiles and installs to $GOBIN

GOBIN defaults to $GOPATH/bin