Setting up the environment

In order to get started with Echo, you will need a working Go environment. To that end, installing Go in your environment is fairly trivial. Firstly, we need to download the Go source code and tool chain and install them. For this book, we will be using Go version 1.9.4, which is the latest release at the time of writing this book. As you can see at https://golang.org/doc/install, there are detailed instructions for setting up your environment correctly. The following are the typical steps needed to install Go for your system:

Linux/macOSX Go Installation

Download Go 1.9.4:

  • Linux:
      curl -O https://dl.google.com/go/go1.10.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz
  • macOS using Homebrew:
      brew install go

Set up related environmental variables (assuming you use bash):

mkdir -p ~/go

echo "export GOPATH=$HOME/go" >> ~/.bashrc

echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc

source ~/.bashrc

At this point, the environment is set up. The preceding curl command downloads Go as a tarball, and the tar command will unpack the Go standard library source code and related binary tools into the /usr/local/go directory on your system. If you are running this as a non-root user, you might need to run the tar command listed in the preceding snippet with root privileges, potentially by changing users to root, or running the command with sudo.

The preceding environment variable setup commands will first set up a workspace as a go directory within your home directory. The command will also set your GOPATH environment variable to use this workspace for downloading go packages. Next, we need to set the PATH variable to include the bin directory that was installed in /usr/local/go/which is where the Go compiler, as well as other tools such as gofmt that come with Go, reside. Finally, we add all of these environment variables into your .bashrc so that every time you log in, these environment variables are set appropriately.

Windows installation

You can download the MSI installer for Go: https://dl.google.com/go/go1.10.windows-amd64.msi.

The Windows installer will, by default, install Go in the c:\Go\ folder. The installer will take care of setting up all necessary environment variables for you.