Initial commit of golang port.

The code was ported largely "as is" from the C version.
Improve formatting.
Merge pull request #1 from benalexau/master

Initial commit of golang port.