rewrite golang implementation

with only standard library