pubsub is a Go module that offers a concurrent pub/sub service leveraging goroutines and channels.
Use the Go CLI tool go to install hmac.
go get github.com/pascalallen/pubsub
...
import (
"fmt"
"github.com/pascalallen/pubsub"
)
...
c := make(chan pubsub.Message)
t := pubsub.CreateTopic("my-topic", c)
m := pubsub.CreateMessage([]byte("hello, jupiter!"))
t.AddMessage(*m)
s := pubsub.CreateSubscriber("my-subscription", *t, c)
go t.Publish()
for m := range s.Channel {
fmt.Printf("Message received for subscriber %s: %s\n", s.Name, m)
}
...
Run tests and create coverage profile:
go test -covermode=count -coverprofile=coverage.out
View test coverage profile:
go tool cover -html=coverage.out
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.