Basics

Environment variables

go env VARIABLE_NAME to view the value of the go environment variable with name VARIABLE_NAME.

go env GOPATH # example value: /Users/fangjun/go
go env GOARCH # example value: amd64, 386, arm
go env GOOS # example value: linux, darwin, windows

go help environment

Hello world

See https://go.dev/doc/tutorial/getting-started

go mod init example/hello

The above command will create a file go.mod in the current directory.

# content of go.mod
module example/hello

go 1.20

Note that go mod init does not create any directories. It only creates a file go.mod with the above content.

verbose build

go build -x -v

exported

For non-builtin functions and variables, if the name begins with an uppercase, then it is exported. Otherwise, it is not exported.

Note that for builtin functions, the above rule does not apply. For instance, both print and println are exported.

go vet

Use go vet to quick check the correctness of the code.