Install Go

OK so you’d like to install it manually. Let’s proceed.

First, let’s install Go.

# OSX

$ brew install go # Ubuntu/ Debian

# We don't bother with the package manager, it's always outdated

$ wget -qO - https://godeb.s3.amazonaws.com/godeb-amd64.tar.gz | tar zxvf - -C /tmp && /tmp/godeb install 1.5 && rm -f /go*.deb

If you’d like to be able to switch easily from one version to another, gvm will play well.

Then you have to define your $GOPATH. This is the directory that will contain all third party libraries, including yours. I like to set it to $HOME/go.

Edit your local .bashrc (Linux/Bash), .bash_profile (OSX), or .zshrc and add the following:

# Go environment

export GOPATH="$HOME/go"

# Expose the Go binaries in the PATH

export PATH="$GOPATH/bin:$PATH"

Then reload your file with source and you are all set! now it’s time to…

Install and configure Sublime Text

You can get it here.

Once installed, you will need to install the second most important thing: Package Control. A sort of package manager for Sublime Text, this is a must-have. The instructions are pretty clear, and so far for me, it always worked. Open the console, copy/paste the snippet, press ENTER.

Restart ST.

The magic starts now. Open the command palette (ctrl+shift+p for Windows/Linux, cmd+shift+p for OSX), type in: “install”, it will automatically resolve the “Package Control: Install Package” command.

Then you can search for “GoSublime” and install it.

Go Development Workflow

I like to get instant feedback while I’m working so that I can address the issues raised right away. Linting, testing, static analysis…

It is common to run these tools in a CI build, this is a good thing to do, but waiting for a report from your CI system is most likely going to end up in procrastination!

So we’re going to configure a hook that will be ran at each Go file save.

Open Preferences > Package Settings > GoSublime > Settings - User, and copy/paste the following.

Notice the goimports set for the fmt_cmd? This part will handle the formatting of your file before it’s saved (using go fmt) and automatically add or remove imports for you.

You’re almost done! We are missing a few tools used above.

go get -u github.com/golang/lint/golint

go get -u golang.org/x/tools/cmd/goimports

Done! Now when you’ll save a Go file, the reports will be automatically fed into the ST console.