Initial commit of golang port.

The code was ported largely "as is" from the C version.