Getting started with Go
I love the Python language for its simplicity and conciseness; and it’s my weapon of choice for quickly hacking up a web app prototype.
But as a site begins to scale and we need to maximize the advantage of multi-core processors, languages that are designed with concurrency and parallelism begin to shine. Â One could go low-level and 2eplace Python modules (code) with C or C++; but one could also explore the possibility of delegating certain tasks to contemporary languages like Erlang, Scala or the-new-kid-on-the-block Go.
It was interesting (to me) that Google decided to create their own language to solve the problem of concurrency and parallelism. Â So here’s me taking a peek at how Go works.
Installing via Google’s provided package -Â http://code.google.com/p/go/downloads/list?q=OpSys-Darwin
The installer created a “go” directory in my /usr/local path placed a bunch of stuff into it. This also makes available “go” in my command line. Â Unfortunately, I got a perms error when I attempted:
calvin$ go get code.google.com/p/go-tour/gotour pack!ge code.google.com/p/go-tour/gotour: mkdir /usr/local/go/src/pkg/code.google.com: permission denied
No big deal, it probably means that the installer did not set my user to the correct owner. Â So checking:-
calvin$ ls -la total 0 drwxr-xr-x 6 root wheel 204 Jul 8 22:21 . drwxr-xr-x@ 14 root wheel 476 May 17 16:13 .. drwxr-xr-x 4 root wheel 136 Jun 12 00:17 bin drwxr-xr-x 6 calvin staff 204 Apr 16 22:01 foreman drwxr-xr-x 19 root wheel 646 Jun 14 11:34 go drwxr-xr-x 6 calvin staff 204 Apr 16 22:01 heroku
The correct way to do this is not to brute force my Go package installation into the /usr/local/go path with a “sudo” but to instead
calvin$ sudo chown -R calvin:staff go
Now, with the correct owner set in place, running the gotour package download works perfectly fine. No more permissions issue.
Calvins-MacBook-Pro.local ttys000 Sun Jul 08 23:39:40 |~/work/go1| calvin$ go get code.google.com/p/go-tour/gotour Calvins-MacBook-Pro.local ttys000 Sun Jul 08 23:40:05 |~/work/go1| calvin$ go go gobject-query godoc gofmt gorbd-mp-4.5 gotour Calvins-MacBook-Pro.local ttys000 Sun Jul 08 23:40:05 |~/work/go1| calvin$ gotour 2012/07/08 23:40:13 Serving content from /usr/local/go/src/pkg/code.google.com/p/go-tour 2012/07/08 23:40:13 Open your web browser and visit http://127.0.0.1:3999/
Onwards, with Go!