ehq / pusher-go

Pusher client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pusher Go Client

img

This is an initial draft of a client library for Pusher, written in Go. So far a few basic features have been implemented, but this is still in no way ready for production environments.

Check out this README or head over to Go Walker.

Installation

Install with the go get command:

go get github.com/ehq/pusher-go

Example Usage

package main

import (
	"encoding/json"
	"github.com/ehq/pusher-go"
	"log"
)

type Move struct {
	X string `json:"x"`
	Y string `json:"y"`
}

func main() {
	client, err := pusher.Connect("your_pusher_key")

	if err != nil {
		log.Fatal(err)
		return
	}

	client.Subscribe("some_channel")

	moves := make(chan Move)

	client.On("move", func(data string) {
		move := Move{}

		json.Unmarshal([]byte(data), &move)

		moves <- move
	})

	for {
		move := <-moves

		log.Printf("New move has been played at x: %s, y: %s", move.X, move.Y)
	}
}

Next steps

The next goals for the project are:

  • Handle disconnects and network problems gracefully
  • Support standard error codes
    • These also determine if a reconnect should be attempted or not.
  • Support system events
  • Encapsulate and refactor the concept of a channel
    • Also include presence channels and private channels (which require authentication)
  • Scope event handlers to channels, rather than making them be global.
  • Implement client events

About

Pusher client library for Go