rewrite to golang