otter

package
v0.0.0-...-541d478 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package otter is a go client for interacting with one or more otter servers.

Subscribing

c := otter.Client{
	Addrs: []string{"127.0.0.1:4444"},
}

pubCh := make(chan otter.Pub)
go func() {
	for p := range pubCh {
		log.Printf("got pub: %#v", p)
	}
}()

for {
	err := c.Subscribe(pubCh, nil, "someChannel")
	log.Printf("got error subscribing: %s", err)
	log.Printf("reconnecting")
}

Backend application client

c := otter.Client{
	Addrs:        []string{"127.0.0.1:4444"},
	PresenceFunc: otter.BackendPresence("secret key"),
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// URLs of otter instances. These will be picked from randomly when making
	// connections to otter. This field should not be changed while there are
	// active connections. A URL should consist of a hostname, path, and
	// scheme.
	URLs []string

	// Used to generate presence strings for connections made by this client.
	// This function will be called on every new connection made. If nil, no
	// presence information is ever used
	PresenceFunc
}

Client is used to connect and interact with otter servers. The only required field is Addrs

func (Client) GetSubscribed

func (c Client) GetSubscribed(subs ...string) ([]conn.Conn, error)

GetSubscribed returns the union of all the connection objects currently subscribed to the given subs. The Client *must* be a backend application in order to use this.

func (Client) Publish

func (c Client) Publish(msg interface{}, subs ...string) error

Publish will publish the given message to all the subs

func (Client) Subscribe

func (c Client) Subscribe(pubCh chan<- Pub, stopCh chan struct{}, subs ...string) <-chan error

Subscribe is used to create a single otter connection which will listen for incoming publishes from the given set of subscriptions. The publishes will be pushed to the given channel.

The returned error channel is buffered by 1, and will have an error written to it if one is encountered, at which point this call is done.

If stopCh is not nil, it can be close()'d by an separate go-routine to close the subsription connection. The returned error channel will be closed in this case.

type PresenceFunc

type PresenceFunc func() (string, string, error)

PresenceFunc is used to provide a presence string and its signature for the otter client. First returned string is the presence string, second is the signature.

func BackendPresence

func BackendPresence(secret string) PresenceFunc

BackendPresence creates a PresenceFunc which can be used by a Client for a backend application

type Pub

type Pub distr.Pub

Pub describes a publish message being received over a subscription connection

Jump to

Keyboard shortcuts

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