pusher-client-go

command module
v0.0.0-...-ac8a552 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2016 License: MIT Imports: 6 Imported by: 0

README

Pusher Websocket Client Go Library

Golang library for connecting to a Pusher App over websockets.

Installing

$ go get github.com/Neopallium/pusher-client-go

Quick start

You can quickly try the library by using the included simple client.

$ pusher-client-go -key APP_KEY -channel TEST_CHANNEL -event EVENT_NAME

Getting Started

package main

import (
  "github.com/Neopallium/pusher-client-go/pusher"
  "sync"
  "fmt"
)

var wg sync.WaitGroup

// Example Handler object
type chanHandler struct {}

func (o *chanHandler) HandleEvent(event pusher.Event) {
  fmt.Println("Handler: Got Event:", event.Channel, event.Event, event.Data)
  wg.Done()
}

// Example Handler function
func eventHandler(event pusher.Event) {
  fmt.Println("HandlerFunc: Got Event:", event.Channel, event.Event, event.Data)
  wg.Done()
}

func main() {
  // Create pusher client connection for "app_key"
  client := pusher.NewClient("app_key")

  // Subscribe to a channel
  ch := client.Subscribe("test_channel")

  wg.Add(10) // wait for 10 events.

  // Bind to events on the channel.  Can use either a Handler object.
  ch.Bind("my_event", &chanHandler{})
  // or Handler callback function.
  ch.BindFunc("my_event", eventHandler)

  // bind to all channel events
  client.BindAll(&chanHandler{})
  client.BindAllFunc(eventHandler)

  // wait for some events.
  wg.Wait()
}

TODO

  • Support private & presence channels. Need auth handler/callback.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL