···11+services:
22+ gossip-gloomers:
33+ container_name: gossip-gloomers
44+ build: .
55+ environment:
66+ - TEST_TO_RUN=placeholder_value
77+ volumes:
88+ # Mount the code in this repo so that the run script can build the app inside the container
99+ # on the fly inside of needing to build the app before hand
1010+ - .:/home/linuxbrew/app
1111+ command: ./run.sh
···11+package main
22+33+import (
44+ "encoding/json"
55+ "log"
66+77+ maelstrom "github.com/jepsen-io/maelstrom/demo/go"
88+)
99+1010+func main() {
1111+ n := maelstrom.NewNode()
1212+ n.Handle("echo", func(msg maelstrom.Message) error {
1313+ // Unmarshal the message body as an loosely-typed map.
1414+ var body map[string]any
1515+ if err := json.Unmarshal(msg.Body, &body); err != nil {
1616+ return err
1717+ }
1818+1919+ // Update the message type to return back.
2020+ body["type"] = "echo_ok"
2121+2222+ // Echo the original message back with the updated message type.
2323+ return n.Reply(msg, body)
2424+ })
2525+2626+ if err := n.Run(); err != nil {
2727+ log.Fatal(err)
2828+ }
2929+}
+7
readme.md
···11+## Gossip Gloomers
22+33+This is my solutions to the [Gossip Gloomers](https://fly.io/dist-sys/) distributed systems problem by fly.io
44+55+I have created a docker image for running the tests inside which can be run using `docker-compose run --rm -e TEST_TO_RUN=echo gossip-gloomers` (replacing the TEST_TO_RUN env to be the test to run).
66+77+Note: The docker image is based off of the `homebrew/brew` image which is quite a whopper of an image so be prepaerd for a longish build time. Need to optimise that to be honest.
+13
run.sh
···11+#!/usr/bin/env bash
22+33+go install .
44+55+# Go back to where maelstrom is so that the additional files that are created when running it
66+# don't end up in the mounted volume and on our local machines
77+cd /home/linuxbrew/maelstrom/
88+99+if [ "$TEST_TO_RUN" = 'echo' ]; then
1010+ ./maelstrom test -w $TEST_TO_RUN --bin /home/linuxbrew/go/bin/gossip-gloomers --node-count 1 --time-limit 10
1111+else
1212+ echo "invalid input"
1313+fi