Move go code out of ragel

Purely go code moved to util.go to make
editing and testing easier.