client

package
v0.0.0-...-79deb2b Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2017 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPayload    error = fmt.Errorf("invalid payload")
	ErrInvalidIdentifier error = fmt.Errorf("invalid identifier")
	ErrRequestTooLarge   error = fmt.Errorf("request too large")
)
View Source
var Discard = &DiscardHandler{}
View Source
var ErrInvalidEvent error = fmt.Errorf("invalid event")

Functions

This section is empty.

Types

type Client

type Client interface {
	// EventHandler retrieves the current EventHandler.
	// This method is safe to call from multiple goroutines simultaneously.
	EventHandler() EventHandler

	// SetEventHandler makes h the current EventHandler.
	// This method is safe to call from multiple goroutines simultaneously.
	SetEventHandler(h EventHandler)

	// Close closes the SSMP client.
	// A CLOSE message is sent to the server before closing the underlying
	// network connection.
	Close()

	// Login makes a LOGIN request.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	Login(user string, scheme string, credential string) (Response, error)

	// Subscribe makes a SUBSCRIBE request.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	Subscribe(topic string) (Response, error)

	// SubscribeWithPresence makes a SUBSCRIBE request with the PRESENCE flag.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	SubscribeWithPresence(topic string) (Response, error)

	// Unsubscribe makes a UNSUBSCRIBE request.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	Unsubscribe(topic string) (Response, error)

	// Ucast makes a UCAST request.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	Ucast(user string, payload string) (Response, error)

	// Mcast makes a MCAST request.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	Mcast(topic string, payload string) (Response, error)

	// Bcast makes a BCAST request.
	// An error is returned in case of network or protocol error. A non-2xx
	// response doesn't cause an error.
	Bcast(payload string) (Response, error)
}

Client is a simple SSMP client wrapper over a network connection.

All requests are blocking and request pipelining is not currently supported.

Unless otherwise specified, it is not safe to invoke methods on a Client from multiple goroutines simultaneously.

func NewClient

func NewClient(c net.Conn, h EventHandler) Client

NewClient creates a new SSMP client using the given network connection and event handler.

type DiscardHandler

type DiscardHandler struct{}

func (*DiscardHandler) HandleEvent

func (h *DiscardHandler) HandleEvent(_ Event)

type Event

type Event struct {
	From    []byte
	Name    []byte
	To      []byte
	Payload []byte
}

Event represents a decoded SSMP server-sent event. All the fields are slices of the client input buffer. They MUST NOT be modified and copies MUST be made if the fields are to be used after the event handler returns.

type EventHandler

type EventHandler interface {
	HandleEvent(event Event)
}

The EventHandler interface is used to react to asynchronous server-sent events.

type Response

type Response struct {
	// Code specifies the response code (200, 400, ...)
	Code int

	// Message is the optional response payload.
	Message string
}

Response represents an SSMP response received by a client.

Jump to

Keyboard shortcuts

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