wango

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2018 License: MIT Imports: 12 Imported by: 8

README

wango

Build Status Coverage Status GoDoc Go Report Card License

Golang high available pub/sub and rpc messaging over WebSockets

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugMode

func DebugMode()

DebugMode sets debug flag after that will print debug messages to stdout

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a websocket connection

func (*Conn) Close

func (c *Conn) Close()

Close closes websocket connection

func (*Conn) Connected

func (c *Conn) Connected() bool

Connected returns true if websocket connection established and not closed

func (*Conn) GetExtra

func (c *Conn) GetExtra() interface{}

GetExtra returns extra data stored in connection

func (*Conn) ID

func (c *Conn) ID() string

ID returns connection ID

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() string

RemoteAddr returns remote address

func (*Conn) Request

func (c *Conn) Request() *http.Request

Request returns related *http.Request

func (*Conn) SendEvent

func (c *Conn) SendEvent(uri string, event interface{}) error

SendEvent sends event for provided uri directly to connection

func (*Conn) SetExtra

func (c *Conn) SetExtra(extra interface{})

SetExtra stores extra data in connection

func (*Conn) StringMode

func (c *Conn) StringMode()

StringMode sets a string mode to use TextFrame encoding for sending messages

type EventHandler

type EventHandler func(uri string, event interface{})

EventHandler is an interface for handlers to published events. The uri is the URI of the event and event is the event centents.

type PubHandler

type PubHandler func(uri string, event interface{}, extra interface{}) (bool, interface{})

PubHandler describes func for handling publish event before sending to subscribers

type RPCHandler

type RPCHandler func(c *Conn, uri string, args ...interface{}) (interface{}, error)

RPCHandler describes func for handling RPC requests

type SubHandler

type SubHandler func(c *Conn, uri string, args ...interface{}) (interface{}, error)

SubHandler describes func for handling RPC requests

type Wango

type Wango struct {
	// contains filtered or unexported fields
}

Wango represents a WAMP server that handles RPC and pub/sub.

func Connect

func Connect(url, origin string, timeout ...time.Duration) (*Wango, error)

Connect connects to server with provided URI and origin

func New

func New(timeout ...time.Duration) *Wango

New creates new Wango and returns pointer to it

func (*Wango) Call

func (w *Wango) Call(uri string, data ...interface{}) (interface{}, error)

Call used for call RPC

func (*Wango) Disconnect

func (w *Wango) Disconnect()

Disconnect used to disconnect all clients in server mode, or to disconnect from server in client mode

func (*Wango) GetConnection

func (w *Wango) GetConnection(id string) (*Conn, error)

GetConnection returns connection for connID provided.

func (*Wango) Publish

func (w *Wango) Publish(uri string, event interface{})

Publish used for publish event

func (*Wango) RegisterRPCHandler

func (w *Wango) RegisterRPCHandler(_uri interface{}, fn func(c *Conn, uri string, args ...interface{}) (interface{}, error)) error

RegisterRPCHandler registers RPC handler function for provided URI

func (*Wango) RegisterSubHandler

func (w *Wango) RegisterSubHandler(uri string, fnSub func(c *Conn, uri string, args ...interface{}) (interface{}, error), fnUnsub func(c *Conn, uri string, args ...interface{}) (interface{}, error), fnPub func(uri string, event interface{}, extra interface{}) (bool, interface{})) error

RegisterSubHandler registers subscription handler function for provided URI. fnSub, fnUnsub and fnPub can be nil. fnSub will called when subscribe event arrived. fnUnsub will called when unsubscribe event arrived. fnPub will called when called Publish method. It can control sending event to connections. If first returned argument is true, then to connection will send data from second argument.

func (*Wango) SendEvent

func (w *Wango) SendEvent(uri string, event interface{}, connIDs []string)

SendEvent sends event for provided uri directly to receivers in slice connIDs

func (*Wango) SetSessionCloseCallback

func (w *Wango) SetSessionCloseCallback(cb func(*Conn))

SetSessionCloseCallback sets callback that will called when connection will closed Callback passes connection struct as only argument.

func (*Wango) SetSessionOpenCallback

func (w *Wango) SetSessionOpenCallback(cb func(*Conn))

SetSessionOpenCallback sets callback that will called when new connection will established. Callback passes connection struct as only argument.

func (*Wango) StringMode

func (w *Wango) StringMode()

StringMode sets a string mode to use TextFrame encoding for sending messages

func (*Wango) Subscribe

func (w *Wango) Subscribe(uri string, fn func(uri string, event interface{}), id ...string) error

Subscribe sends subscribe request for uri provided.

func (*Wango) Unsubscribe

func (w *Wango) Unsubscribe(uri string, id ...string) error

Unsubscribe sends unsubscribe request for uri provided

func (*Wango) WampHandler

func (w *Wango) WampHandler(ws *websocket.Conn, extra interface{})

WampHandler handles every *websocket.Conn connection If extra data provided, it will kept in connection and will pass to rpc/pub/sub handlers

Jump to

Keyboard shortcuts

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