Category Archives: Development

Starting out with Go lang

This is the first technical post we have written on the Teapot Table blog. We want to share what we’ve learnt, to help others and get valuable feedback. This post will discuss starting out with go lang.

After version 1.1 of Go was released, we at Teapot Table thought it may be a good time to jump in and see what all the fuss is about.

The speed of Go was one of the main reasons to choosing it. It was Python or Go and although Python is a much more mature language, we decided to go for something new.

First Impressions

Go is strict. Very strict. There are good and bad points about this, the good may out way the bad – but it can still be very annoying.
All those notices you ignore with other languages will stop Go from running your code, which is good, it forces you to code better. The annoying bit is that it will refuse to run even smaller ‘problems’ like unused variables and imports. This is good for production code, but when developing and testing really gets to you, continually having to comment things in and out.
Getting external libraries is easy, a nice go get command and the URL of it downloads it for you.

Go lang differences

When I first started the subtle syntax and convention differences caught me out.
This is by no means an exhaustive list, but here are a few that I found early on:

  • Use ” double quotes not ‘ single quotes in a string. Go doesn’t like single quotes
  • Use the plus + operator to append strings together not full stops.
  • No semicolons
  • Doesn’t care about tabbing
  • No brackets around if statements
  • Must use curly brackets – on if statements, for etc
  • Every variable must be used
  • functions can return multiple variables
  • its nil not null

How to install Go 1.1 on CentOS

First make sure you have GIT and Mercurial installed
yum install git
yum install mercurial

These are used to get external libraries with the go get command.
tar -C /usr/local -xzf go1.1.linux-amd64.tar.gz

That’s go installed, lets add the path.
vi /etc/profile

Press i to edit, then go to the bottom of the file and add these two lines:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go

Press escape, then type :wq – this’ll save the file and quit

Now Go should be available with the go command. Use go get to install libraries from Github and Google code. Use go run filename.go to run your code!