This is a work in progress so please do not assume this is correct.
Any mistakes in the code are most likely mine.
This code is a port to Golang of the code found at the Marginally
Clever
blog, which is in turn sample code from the Trossen
Robotics
forum] (sadly the link doesn't work at the time of writing).