Next: , Previous: , Up: Introduction to Go   [Index]


Code Examples

All but the most trivial code examples in the book are available for download from the public Git repository at gopl.io.

Each example is identified by its package import path and may be conveniently fetched, built, and installed using the go get command.

Go Workspace: ‘GOPATH’ Environment Variable

You’ll need to choose a directory to be your Go workspace and set the ‘GOPATH’ environment variable to point to it. The go tool will create the directory if necessary.

For example:

$ go version                    # need at least version 1.5 of Go
go version go1.5 linux/amd

$ export GOPATH=$HOME/gobook    # choose workspace directory
$ go get gopl.io/ch1/helloworld # fetch, build, install
$ $GOPATH/bin/helloworld        # run
Hello