Go client library for peer applications running under The Mule test orchestrator.
package main
import (
"context"
"log/slog"
the_mule "github.com/cryptidtech/the-mule/lib/go"
)
func main() {
ctx := context.Background()
client, err := the_mule.NewBuilder().Build(ctx)
if err != nil {
panic(err)
}
defer client.Close()
client.SendStatus(ctx, "started")
for cmd := range client.Commands() {
slog.Info("received", "command", cmd)
if cmd == "shutdown" {
client.SendStatus(ctx, "stopped")
break
}
}
}| Variable | Required | Description |
|---|---|---|
REDIS_URL |
yes | Redis connection URL |
PEER_NAME |
yes | This peer's name |
- Commands: a goroutine calls
BLPOP {peer}_command 0(truly blocking, no polling) and sends raw strings to a buffered Go channel. Context cancellation is respected — when the context is cancelled orClose()is called, the goroutine exits and the channel is closed. Go's M:N scheduler ensures the blocking goroutine does not block your other goroutines. - Logs: a
slog.Handlercaptures log records and forwards them to Redis viaLPUSH {peer}_log "level|message". - Status:
SendStatus()callsSET {peer}_status <value>, which triggers a keyspace notification on the orchestrator side.
NewBuilder()— reads env vars.RedisURL(url)/.PeerName(name)— override.Build(ctx)— connect, install slog handler, start command goroutineMuleClient.SendStatus(ctx, status)— push status to orchestratorMuleClient.Commands()— returns<-chan stringyielding commandsMuleClient.Close()— stop listener and close Redis