Documentation ¶
Overview ¶
The Golang client for PuSu Engine. PuSu Engine is a (relatively) fast and scalable Pub-Sub message delivery system.
The Golang client is a simple (mostly) synchronous client that does little magic internally. For operations that the server acknowledges (Connect, Authorize, Subscribe) it waits for the appropriate event coming back from the server before continuing, to ensure you don't do stupid things and get unexpected results.
Example usage
package main import ( "fmt" "github.com/PuSuEngine/gopusu" ) func main() { pc, _ := gopusu.NewPuSuClient("127.0.0.1", 55000) defer pc.Close() pc.Authorize("foo") pc.Subscribe("channel.1", listener) pc.Publish("channel.2", "message") } func listener(msg *gopusu.Publish) { fmt.Printf("Got message %s on channel %s\n", msg.Content, msg.Channel) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTimeoutExceeded = errors.New("Timeout exceeded when waiting for server to acknowledge message")
Timeout exceeded when waiting to acknowledge Authorize/Subscribe request
Functions ¶
This section is empty.
Types ¶
type Client ¶
The PuSu client. Create one of these with NewClient(), and call the Authorize(), Subscribe() and Publish() methods to communicate with the PuSu network.
func (*Client) Authorize ¶
Claim you have authorization to access some things. The server will determine what those things could be based on the configured authenticator and the data you give. Expect to get disconnected if this is invalid.
func (*Client) Subscribe ¶
func (pc *Client) Subscribe(channel string, callback SubscribeCallback) error
Ask to subscribe for messages on the given channel. You MUST use the Authorize() method before this, even if server is configured to use the "None" authenticator. Expect to get disconnected if you lack the permissions.
type Publish ¶
type Publish struct { Type string `json:"type"` Channel string `json:"channel"` Content string `json:"content"` }
Published message from the PuSu network. You get these to your callback if you subscribe to a channel.
type SubscribeCallback ¶
type SubscribeCallback func(*Publish)
Callback to call with the published messages in a channel we're subscribed to.