Wednesday, December 14, 2011


While working on something else, I need to write a little utility function that returns a range of days. (When the new time package make it to release, this should be much simpler).

Tuesday, December 6, 2011

AppEngine Demo - URL Shortener

Here you can find a small AppEngine Go example.It is a URL shortener (like I shows the following capabilities:
  • HTTP Serving
  • Templates
  • Datastore
  • Task Queue
  • Logging
  • Memcache
Below is the main application code:

Sunday, November 27, 2011

Reversim Interview

Had great fun talking about Go with Ran and Ori at Reversim.
You can listen to the podcast here (note: it's in Hebrew).

Tuesday, November 8, 2011

A simple atexit library

Go does not have an atexit library (and will probably never have). Below is a small implementation of such a library. Note that you have to use atexit.Exit and not os.Exit in your program.

As usual, you can install with goinstall
And here is an example program (the funky import is due to running this program as a test in the source directory)

Monday, October 24, 2011


The expvar let you expose variables via HTTP/JSON protocol. Here at Adconion we call these metrics, and more than once they have been very instrumental in debugging and monitoring services.

We usually combine the metrics with an external monitoring system such as Nagios or OpenNMS. We set some thresholds for alerts and also chart some of them metrics over time.

Below is a small demo on how to use the package.

Thursday, October 20, 2011

Tuesday, October 11, 2011

Number → English

Had some fun converting to Go and making it a web service.

Friday, October 7, 2011

Running Tests In Parallel

As of weekly.2011-10-06, parallel testing is here. In order to have you test run in parallel, add a call to t.Parallel() at the top of your test function. Then run gotest with --parallel N (where N > 1).

Things to notice:
  • A parallel test run in parallel only to other parallel tests. That means your non-parallel tests will run first and then your parallel ones.
  • A maximum of --parallel (a new gotest command line switch) tests will run in parallel. --parallel defaults to runtime.GOMAXPROCS(0) which is 1. This means the if you don't specify --parallel, your parallel tests will run one at a time.

Monday, September 26, 2011

Simulate event with closing a channel

rog had showed me a nice way to synchronise several goroutines (something like an event) by closing a channel. Here's a code example:

Friday, September 16, 2011

Copy Directory Tree

filepath.Walk is a very useful function. Here's how you can use it to copy a directory tree:

Tuesday, September 13, 2011

Go on Hadoop

It's easy to use Go (or any other language) with Hadoop streaming. Here's a little "word count" example.

System Setup:
  • Hadoop running locally (Cloudera cdh3u0)
  • A copy of hadoop-streaming-0.20.2-cdh3u0.jar in local directory
  • Copy of "Alice In Wonderland" under /user/miki/alice.txt on HDFS


After the job has ran, you can view the output and check the most common words:

hadoop fs -cat /user/miki/words-out/part-00000 | sort -k 2 -n -r | head
the	1686
and	869
to	799
a	672
of	606
I	545
it	540
she	509
said	456
in	414

Sunday, September 4, 2011

A Selenium Client

Just released a new client for Selenium (remote WebDriver to be exact). Still work in progress but usable.


Example usage (you'll need a running Selenium server):

Thursday, September 1, 2011

Using ctags with Go

I'm a Vim user, and using ctags with it help me quickly navigate through code. ctags does not come with support for Go (yet?). But it's easy to add new language support to it using custom regular expressions. The below code will detect function definition in Go files. Then after running ctags -R in your project root you can hit CTRL-[ in Vim to jump to function definition.

Add the following to ~/.ctags:

Oh, and you should check out gocode as well.

Monday, August 29, 2011

Logging to Multiple Destinations

By default, the log package logs to standard output. However a lot of time I like to log both to screen and to a log file. This is where io.MultiWriter comes in handy, just wrap os.Stdout and your log file in one of these and you're good to go.

Below is a small example on how to do that:
/* MIKI: Analytics */