cobbling together a golang development environment

January 18, 2015

golangOver the weekend, in between all the other tasks I do as husband, father, home owner and tax payer, I cobbled together a Go programming environment using Vim on my Ubuntu 14.10 notebook. Adding this capability required that I install Go, Go tools, and a series of Vim plugins pulled from Github.

Why Go?

I chose to go to Go (or golang) as a programming environment, specifically on the Raspberry Pi, because I’d finally had my fill of the node.js and the Io.js fork melodrama. I’d already grown quite tired of how Joyent was handling the stewardship of node.js and was loosing faith that node.js would stay up to date, such as running with Google’s latest V8 Javascript engine. In the end I decided I needed more of a mature language and supporting development tools written and managed by real adults. That’s when I decided to give a go with Go.

Go, in case you’re curious, is aimed more at systems level programming (which is where I tend to reside). Go is also a Google product, invented by two of the most iconic hackers the software world knows: Rob Pike and Ken Thompson. I know of Rob Pike primarily through his book “The Unix Programming Environment” he wrote along with Brian Kernighan. I’ve had that book since the late 1980s, along with “The C Programming Language.” That latter book was co-written by Ken Thompson along with Brian Kernighan (as well). And, of course, in his spare time, Ken Thompson was the principal inventor of Unix. And they’re now both working for Google Research.

Beyond Go’s stellar heritage, there are many reasons to use Go. Two that come immediately to my mind are Go’s ability to work closely with C/C++ code and Dave Cheney’s “Unofficial ARM Tarballs for Go” for various ARM-based tiny computers. One of the unofficial ARM targets is ARM6 and the Raspberry Pi. A second target is ARM7 and the Beagle Bone Black Rev C. The goal of this exercise is thus in two parts: get Go tooling up and running under Ubuntu, start developing Go under Ubuntu, run the products of said development under Raspbian on the Raspberry Pi using one of the unofficial tarballs, then move the entire development environment over to the Raspberry Pi itself if all of that works satisfactorily.

If Go is a poor fit on the RPi and BBB, then I intent to drop back to good ol’ C and C++. I’m done with node.js and Javascript.

Golang Setup under Ubuntu 14.10

Setting up Go is straightforward in Ubuntu (or another other major OS). The best way is to go follow the steps on the Golang site: download, follow the directions exactly, and then you’re done. That sets up the initial Go build/run environment, and you can start writing code from that point. For this exercise I downloaded and installed Go 1.4.1.

But I wanted more. I wanted an IDE, or the equivalent thereof, for Go code development. I wanted to use Vim specifically because I didn’t want to have to run a graphical desktop on the Raspberry Pi; I wanted to run on the console. In the end I chose to use Vim as my Go IDE and found reasonably current directions at myitcv:blog, “Programming with Go in Vim.”

The blog entry has everything you need to do broken down in easy-to-follow steps. Here are my comments on those steps.

  1. My version of Vim was the same, but built October 2014.
  2. I downloaded and installed Go version 1.4.1.
  3. I know how to add Vim plugins, and that’s the route I chose.
  4. For installing godef, make sure you have Mercurial installed. I didn’t and installation failed the first time.
  5. I installed all the plugins via git clone from Github. I’m using Pathogen to rule them all.

Screenshot from 2015-01-18 23:08:53Here’s Vim performing an IDE-like function, code completion in a tiny snippet of Go code. It was this feature I wanted more than any other. I can keep the general language in my head, but code completion helps to “remember” it all. I do need to tweak the colors a bit; gray on purple doesn’t quite make it (white or yellow would be better), but it’s usable regardless. Here’s my .vimrc with what I’ve enabled so far. It will change quickly.

execute pathogen#infect()
filetype plugin on
set omnifunc=syntaxcomplete#Complete

colo elflord
syntax on
set nu

set autoread
set ruler
set cmdheight=2

set expandtab
set smarttab
set shiftwidth=4
set tabstop=4

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

let g:godef_split=3
let g:godef_same_file_in_same_window=1

I’ll keep updating this as I go along, with seperate posts, but for now it’s operational enough for me to learn how to write Go code. More to follow…