goatee

package module
v0.0.0-...-3a10a32 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2014 License: MIT Imports: 9 Imported by: 0

README

goatee

A Redis-backed notification server written in Go.

Build Status

##Installation go get github.com/johnernaut/goatee

import "github.com/johnernaut/goatee"

##Usage goatee works by listening on a channel via Redis Pub/Sub and then sending the received message to connected clients via WebSockets.

Configuration

goatee will look for a JSON configuration file in a config folder at the root of your project with the following names based on your environment: development.json, production.json, etc. By default config/development.json will be used but you can also specify a GO_ENV environment variable and the name of that will be used instead.

// example json configuration
// specify redis and websocket hosts
{
  "redis": {
    "host": "localhost:6379"
  },
  "web": {
    "host": "localhost:1235"
  }
}

======

Server
package main

import (
    "github.com/johnernaut/goatee"
    "log"
)

func main() {
    err := goatee.CreateServer("achannel") // pass in the redis channel you'd like to subscribe to

    if err != nil {
        log.Fatal("Error: ", err.Error())
    }
}

========

Client
<!doctype html>
<html>
  <head><title>goatee</title></head>
  <body>
    <h1>Websocket Messages:</h1>
    <ul id="ws">
    </ul>
  </body>
  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  <script>
    var ws = new WebSocket("ws://localhost:1235/"); // based on the websocket host set in your config file
    ws.onopen = function() {
      console.log('opened!');
    }
    ws.onclose = function(e) {
      console.log('closed!' + e.code);
    }
    ws.onerror = function(error) {
      console.log("Error: " + error);
    }
    ws.onmessage = function(e) {
      $('#ws').append('<li>' + e.data + '</li>');
    }
  </script>
</html>

========

Redis

With goatee running and your web browser connected to the socket, you should now be able to test message sending from Redis to your client (browser). Run redis-cli and publish a message to the channel you subscribed to in your Go server. E.x. publish 'mychannel' 'mymessage'

Tests

go test github.com/johnernaut/goatee

Authors

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEBUG  = false
	Config = new(configuration)
)
View Source
var H = sockethub{
	Broadcast: make(chan []byte),
	// contains filtered or unexported fields
}

Functions

func CreateServer

func CreateServer(redisub string) error

func LoadConfig

func LoadConfig(path string) *configuration

func NotificationHub

func NotificationHub(host string) error

func WsHandler

func WsHandler(w http.ResponseWriter, r *http.Request)

Types

type Client

type Client interface {
	Publish(channel, message string)
	Receive() (message Message)
}

type Message

type Message struct {
	Type    string
	Channel string
	Data    string
}

type Redis

type Redis struct {
	Host string
}

type RedisClient

type RedisClient struct {
	redis.PubSubConn
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRedisClient

func NewRedisClient(host, sub string) (*RedisClient, error)

func (*RedisClient) Publish

func (client *RedisClient) Publish(channel, message string)

func (*RedisClient) PubsubHub

func (client *RedisClient) PubsubHub()

func (*RedisClient) Receive

func (client *RedisClient) Receive() Message

type Web

type Web struct {
	Host string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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