https://github.com/deliveroo/routemaster-client-go
Routemaster Client written in Go
https://github.com/deliveroo/routemaster-client-go
golang library routemaster routemaster-client
Last synced: 6 months ago
JSON representation
Routemaster Client written in Go
- Host: GitHub
- URL: https://github.com/deliveroo/routemaster-client-go
- Owner: deliveroo
- Archived: true
- Created: 2017-08-17T17:07:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T20:52:50.000Z (about 3 years ago)
- Last Synced: 2024-06-20T14:27:31.034Z (about 2 years ago)
- Topics: golang, library, routemaster, routemaster-client
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 2
- Watchers: 11
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Routemaster Client
[](https://travis-ci.com/deliveroo/routemaster-client-go)
[](http://godoc.org/github.com/deliveroo/routemaster-client-go)
`package routemaster`
A Go API client and listener for the Routemaster event bus.
## Usage
First, create a new client:
```go
c, err := routemaster.NewClient(&routemaster.Config{
URL: "https://routemaster.dev",
UUID: "demo",
})
```
### Commands
#### Subscribe
To subscribe to one or more topics:
```go
c.Subscribe(&routemaster.Subscription{
Topics: []string{"widgets"},
Callback: "https://app.example.com/events",
UUID: "demo",
}))
```
#### Unsubscribe
To unsubscribe from a single topic:
```go
c.Unsubscribe("widgets")
```
To unsubscribe from all topics:
```go
c.UnsubscribeAll()
```
#### Push
To push an event to the bus:
```go
c.Push("widgets", &routemaster.Event{
Type: "create",
URL: "https://app.example.com/widgets/1",
Data: map[string]interface{}{
"color": "teal",
},
})
```
#### Listen
To listen to events published on the bus:
```go
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)
```