4 May 2022

Quick Go Dump

I am working on porting a Go SDK to Rust. My goal right now is to figure out the I/Os of a certain SDK function and replicate it in go.

I’m an lucky the previous maintainers provided an in memory client, which I should be able to override and json dump all the I/Os, which should become the input for my rust SDK tests.


This is the commit where I test this approach:


It’s a [[TestGround]] hack.

Anonymous Structs

Define the struct and create it at the same time. It’s the fastest way to hack around and get a readable JSON output in cases where you want some data and it’s not straightforward to start a go debugger.

(see below why)

	i.operations = append(i.operations, Operation{Kind: "barrier", Payload: struct {
		State  State `json:"state"`
		Target int   `json:"target"`
		State:  state,
		Target: target,

Build in docker

docker run -t -i --rm --volume $PWD:/pwd golang:1.17-buster bash

That’ll mount the current folder and let you build from a docker / linux / buster image. Useful when you work on a piece of go code that doesn’t build on macos.

JSON Marshal indent

func (i *inmemClient) DumpIO() error {
	bytes, err := json.MarshalIndent(i.operations, "", "  ")

	if err != nil {
		return err

	return nil

Laurent Senta

I wrote software for large distributed systems, web applications, and even robots. Now I focus on decentralization, overly-engineered software, and frugal innovation. I help companies around the world build products through SingularGarden.