main.go 468 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "math/rand"
  6. "time"
  7. "github.com/ably/ably-go/ably"
  8. )
  9. func main() {
  10. opt := &ably.ClientOptions{}
  11. opt.Key = "kY92tg.1qo8DQ:CS755GfXwEGtBiIr"
  12. a, err := ably.NewRealtimeClient(opt)
  13. panicIfErr(err)
  14. chn := a.Channels.Get("test")
  15. for {
  16. log.Println("Sending:")
  17. chn.Publish("test", fmt.Sprintf("Hello: %d", rand.Intn(10)))
  18. <-time.After(2 * time.Second)
  19. }
  20. }
  21. func panicIfErr(err error) {
  22. if err != nil {
  23. panic(err)
  24. }
  25. }