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 ¶
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) Subscribe ¶
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 ¶
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