satori-go allows you to interact with the Satori platform to create server-based or mobile applications that use the RTM to publish and subscribe.
Sign up/sign in here: https://developer.satori.com/#/
go get github.com/ericdmann/satori-go
Publisher and subscription examples are located inside of /examples
rtmClient, err := rtm.NewClient(RTMEndpoint, RTMAppKey, RTMRoleName, RTMRoleSecret, true)
RTMEndpoint // See satori documentation for endpoint
RTMAppKey // See satori documentation for app key
RTMRoleName // See satori documentation for role name
RTMRoleSecret // See satori documentation for role secret
Debug // Triggers logging on each RTM action
Once a client has been created, publishing to a channel is quite simple.
rtWire, err := rtmClient.Publish(channel, map[string]interface{}{"time": time.Now().String()})
Each client can subscribe to exacly one channel at a time. Subscriptions can be changed without reconnecting.
err = rtmClient.Subscribe(channel)
Because there is only one active subscription per client, you can cancel without providing a channel name.
err = rtmClient.CancelSubscription()
Each client has a subscription channel chan RTWire
. Trigger items to be pulled off of the socket and put on this channel by calling ReadSubscription()
go rtmClient.ReadSubscription()
for {
item := <-rtmClient.Subscription
fmt.Println("(Received) : ", item.Body.Messages)
}
Publisher and subscription examples are located inside of /examples
go run subscribe.go
Export all the necessary Satori fields into your environment by using the export
built-in:
$ export SATORI_APP_KEY=<YOUR_SATORI_APP_KEY>
You can then just use go test --cover
PASS
coverage: 82.2% of statements
ok 1.942s
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
- Auto reconnect (currently will need refreshed)