goatee

package module
v0.0.0-...-657db3b Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2014 License: MIT Imports: 10 Imported by: 0

README

goatee

A Redis-backed notification server written in Go.

Build Status

Client library: goatee.js

##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. Clients may create channels to listen on by using the goatee client library.

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() {
    // subscribe to one or many redis channels
    err := goatee.CreateServer()

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

========

Client

An example of how to use the goatee client library can be found in the examples folder.

========

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. By default, goatee expects your Redis messages to have a specified JSON format to send to the client with the following details:

  • payload
  • created_at (optional)

E.x. publish 'mychannel' '{"payload": "mymessage which is a string, etc."}'

Tests

go test github.com/johnernaut/goatee

Authors

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEBUG  = false
	Config = new(configuration)
)

Functions

func CreateServer

func CreateServer() sockethub

func LoadConfig

func LoadConfig(path string) *configuration

Types

type Client

type Client interface {
	Receive() (message Message)
}

type Data

type Data struct {
	Channel   string `json:"channel"`
	Payload   string `json:"payload"`
	CreatedAt string `json:"created_at"`
}

type Message

type Message struct {
	Type    string
	Channel string
	Data    []byte
}

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 string) (*RedisClient, error)

func (*RedisClient) PubsubHub

func (client *RedisClient) PubsubHub()

func (*RedisClient) Receive

func (client *RedisClient) Receive() Message

type WSClient

type WSClient struct {
	Channel string `json:"channel"`
	Action  string `json:"action"`
	Date    string `json:"date"`
	Payload string `json:"payload"`
	Token   string `json:"token"`
}

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