Eric Bower
·
2026-01-25
README.md
1# pubsub
2
3A generic pubsub implementation for Go.
4
5```go
6package main
7
8import (
9 "bytes"
10 "context"
11 "fmt"
12 "log/slog"
13
14 "github.com/picosh/pubsub"
15)
16
17func main() {
18 ctx := context.TODO()
19 logger := slog.Default()
20 broker := pubsub.NewMulticast(logger)
21
22 chann := []*pubsub.Channel{
23 pubsub.NewChannel("my-topic"),
24 }
25
26 go func() {
27 writer := bytes.NewBufferString("my data")
28 _ = broker.Pub(ctx, "pubID", writer, chann, false)
29 }()
30
31 reader := bytes.NewBufferString("")
32 _ = broker.Sub(ctx, "subID", reader, chann, false)
33
34 // result
35 fmt.Println("data from pub:", reader)
36}
37```
38
39## pubsub over ssh
40
41The simplest pubsub system for everyday automation needs.
42
43Using `wish` we can integrate our pubsub system into an SSH app.
44
45[](https://asciinema.org/a/674287)
46
47```bash
48# term 1
49mkdir ./ssh_data
50cat ~/.ssh/id_ed25519 ./ssh_data/authorized_keys
51go run ./cmd/example
52
53# term 2
54ssh -p 2222 localhost sub xyz
55
56# term 3
57echo "hello world" | ssh -p 2222 localhost pub xyz
58```