A Go client library for ably.io, the real-time messaging service.
~ $ go get -u github.com/ably/ably-go/ably
client, err := ably.NewRealtimeClient(ably.NewClientOptions("xxx:xxx"))
if err != nil {
panic(err)
}
channel := client.Channel.Get("test")
sub, err := channel.Subscribe()
if err != nil {
panic(err)
}
for msg := range sub.MessageChannel() {
fmt.Println("Received message:", msg)
}
sub, err := channel.Subscribe("EventName1", "EventName2")
if err != nil {
panic(err)
}
for msg := range sub.MessageChannel() {
fmt.Println("Received message:", msg)
}
// send request to a server
res, err := channel.Publish("EventName1", "EventData1")
if err != nil {
panic(err)
}
// await confirmation
if err = res.Wait(); err != nil {
panic(err)
}
// send request to a server
res, err := channel.Presence.Enter("presence data")
if err != nil {
panic(err)
}
// await confirmation
if err = res.Wait(); err != nil {
panic(err)
}
// send request to a server
res, err := channel.Presence.EnterClient("clientID", "presence data")
if err != nil {
panic(err)
}
// await confirmation
if err = res.Wait(); err != nil {
panic(err)
}
clients := channel.Presence.Get(true)
for _, client := range clients {
fmt.Println("Present client:", client)
}
sub, err := channel.Presence.Subscribe()
if err != nil {
panic(err)
}
for msg := range sub.PresenceChannel() {
fmt.Println("Presence event:", msg)
}
sub, err := channel.Presence.Subscribe(proto.PresenceEnter)
if err != nil {
panic(err)
}
for msg := range sub.PresenceChannel() {
fmt.Println("Presence event:", msg)
}
All examples assume a client and/or channel has been created as follows:
client, err := ably.NewRestClient(&ably.ClientOptions{Key: "xxx:xxx"})
if err != nil {
panic(err)
}
channel := client.Channel("test")
err := channel.Publish("HelloEvent", "Hello!")
if err != nil {
panic(err)
}
page, err := channel.History(nil)
for ; err == nil; page, err = page.Next() {
for _, message := range page.Messages() {
fmt.Println(message)
}
}
if err != nil {
panic(err)
}
page, err := channel.Presence.Get(nil)
for ; err == nil; page, err = page.Next() {
for _, presence := range page.PresenceMessages() {
fmt.Println(presence)
}
}
if err != nil {
panic(err)
}
page, err := channel.Presence.History(nil)
for ; err == nil; page, err = page.Next() {
for _, presence := range page.PresenceMessages() {
fmt.Println(presence)
}
}
if err != nil {
panic(err)
}
client.Auth.RequestToken()
client.Auth.CreateTokenRequest()
page, err := client.Stats()
for ; err == nil; page, err = page.Next() {
for _, stat := range page.Stats() {
fmt.Println(stat)
}
}
if err != nil {
panic(err)
}
As the library is actively developed couple of features are not there yet:
- Realtime connection recovery is not implemented
- Realtime connection failure handling is not implemented
- ChannelsOptions and CipherParams are not supported when creating a Channel
- Realtime Ping function is not implemented
Please visit http://support.ably.io/ for access to our knowledgebase and to ask for any assistance.
You can also view the community reported Github issues.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Ensure you have added suitable tests and the test suite is passing (
make test
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Copyright (c) 2015 Ably Real-time Ltd, Licensed under the Apache License, Version 2.0. Refer to LICENSE for the license terms.