···1+services:
2+ gossip-gloomers:
3+ container_name: gossip-gloomers
4+ build: .
5+ environment:
6+ - TEST_TO_RUN=placeholder_value
7+ volumes:
8+ # Mount the code in this repo so that the run script can build the app inside the container
9+ # on the fly inside of needing to build the app before hand
10+ - .:/home/linuxbrew/app
11+ command: ./run.sh
···1+package main
2+3+import (
4+ "encoding/json"
5+ "log"
6+7+ maelstrom "github.com/jepsen-io/maelstrom/demo/go"
8+)
9+10+func main() {
11+ n := maelstrom.NewNode()
12+ n.Handle("echo", func(msg maelstrom.Message) error {
13+ // Unmarshal the message body as an loosely-typed map.
14+ var body map[string]any
15+ if err := json.Unmarshal(msg.Body, &body); err != nil {
16+ return err
17+ }
18+19+ // Update the message type to return back.
20+ body["type"] = "echo_ok"
21+22+ // Echo the original message back with the updated message type.
23+ return n.Reply(msg, body)
24+ })
25+26+ if err := n.Run(); err != nil {
27+ log.Fatal(err)
28+ }
29+}
+7
readme.md
···0000000
···1+## Gossip Gloomers
2+3+This is my solutions to the [Gossip Gloomers](https://fly.io/dist-sys/) distributed systems problem by fly.io
4+5+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).
6+7+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
···0000000000000
···1+#!/usr/bin/env bash
2+3+go install .
4+5+# Go back to where maelstrom is so that the additional files that are created when running it
6+# don't end up in the mounted volume and on our local machines
7+cd /home/linuxbrew/maelstrom/
8+9+if [ "$TEST_TO_RUN" = 'echo' ]; then
10+ ./maelstrom test -w $TEST_TO_RUN --bin /home/linuxbrew/go/bin/gossip-gloomers --node-count 1 --time-limit 10
11+else
12+ echo "invalid input"
13+fi