This should take you about 1 min to read.
and it will need to return a “generate_ok” message with a unique ID:
IDs may be of any type-strings, booleans, integers, floats, arrays, etc.
package main
import (
"encoding/json"
"log"
maelstrom "github.com/jepsen-io/maelstrom/demo/go"
"github.com/google/uuid"
)
func main() {
n := maelstrom.NewNode()
n.Handle("generate", func(msg maelstrom.Message) error {
var body map[string] any
if err := json.Unmarshal(msg.Body, &body); err != nil {
return err
}
body["type"] = "generate_ok"
body["id"] = uuid.NewString()
return n.Reply(msg, body)
})
if err := n.Run(); err != nil {
log.Fatal(err);
}
}
This technically passes the test requirement but, uhm, feels too easy and not challenging? Maybe I should look into chronologically generating my own IDs that are network independent.