package routemaster
A Go API client and listener for the Routemaster event bus.
First, create a new client:
c, err := routemaster.NewClient(&routemaster.Config{
URL: "https://routemaster.dev",
UUID: "demo",
})
To subscribe to one or more topics:
c.Subscribe(&routemaster.Subscription{
Topics: []string{"widgets"},
Callback: "https://app.example.com/events",
UUID: "demo",
}))
To unsubscribe from a single topic:
c.Unsubscribe("widgets")
To unsubscribe from all topics:
c.UnsubscribeAll()
To push an event to the bus:
c.Push("widgets", &routemaster.Event{
Type: "create",
URL: "https://app.example.com/widgets/1",
Data: map[string]interface{}{
"color": "teal",
},
})
To listen to events published on the bus:
http.Handle("/", routemaster.NewListener(
"demo",
func(events []*routemaster.ReceivedEvent) error {
for _, e := range events {
log.Printf("%v\n", e)
}
})
))
http.ListenAndServeTLS(":8123", "server.crt", "server.key", nil)