turnpike: github.com/mattbaird/turnpike Index | Files | Directories

package turnpike

import "github.com/mattbaird/turnpike"

Package turnpike provides a Websocket Application Messaging Protocol (WAMP) server and client

Index

Package Files

client.go prefix.go server.go turnpike.go wamp.go

Variables

var (
    // An ErrInvalidURI describes an invalid URI.
    ErrInvalidURI = &WAMPError{"invalid URI"}
    // An ErrInvalidNumArgs describes invalid number of arguments in a message.
    ErrInvalidNumArgs = &WAMPError{"invalid number of arguments in message"}
    // An ErrUnsupportedProtocol describes an unsupported WAMP protocol in a welcome message.
    ErrUnsupportedProtocol = &WAMPError{"unsupported protocol"}
)

type CallResult Uses

type CallResult struct {
    // Result contains the RPC call result returned by the server.
    Result interface{}
    // Error is nil on call success otherwise it contains the RPC error.
    Error error
}

CallResult represents either a sucess or a failure after a RPC call.

type Client Uses

type Client struct {
    // SessionId is a ID of the session in UUID4 format received at the start of the session.
    SessionId string
    // ProtocolVersion is the version of the WAMP protocol received at the start of the session.
    ProtocolVersion int
    // ServerIdent is the server ID (ie "turnpike, autobahn") received at the start of the session.
    ServerIdent string
    // contains filtered or unexported fields
}

Client represents a WAMP client that handles RPC and pub/sub.

func NewClient Uses

func NewClient() *Client

NewClient creates a new WAMP client.

func (*Client) Call Uses

func (c *Client) Call(procURI string, args ...interface{}) chan CallResult

Call makes a RPC call on the server identified by procURI (in either full URI or CURIE format) with zero or more args. Returns a channel that will receive the call result (or error) on completion.

Ref: http://wamp.ws/spec#call_message

func (*Client) Connect Uses

func (c *Client) Connect(server, origin string) error

Connect will connect to server with an optional origin. More details here: http://godoc.org/code.google.com/p/go.net/websocket#Dial

func (*Client) ConnectWithHeaders Uses

func (c *Client) ConnectWithHeaders(server, origin string, headers map[string]string) error

func (*Client) Disconnect Uses

func (c *Client) Disconnect() error

func (*Client) Prefix Uses

func (c *Client) Prefix(prefix, URI string) error

Prefix sets a CURIE prefix at the server for later use when interacting with the server. prefix is the first part of a CURIE (ie "calc") and URI is a full identifier (ie "http://example.com/simple/calc#") that is mapped to the prefix.

Ref: http://wamp.ws/spec#prefix_message

func (*Client) Publish Uses

func (c *Client) Publish(topicURI string, event interface{}, opts ...interface{}) error

Publish publishes an event to the topicURI that gets sent to all subscribers of that topicURI by the server. opts can can be either empty, one boolean that can be used to exclude outself from receiving the event or two lists; the first a list of clients to exclude and the second a list of clients that are eligible to receive the event. Either list can be empty.

Ref: http://wamp.ws/spec#publish_message

func (*Client) PublishExcludeMe Uses

func (c *Client) PublishExcludeMe(topicURI string, event interface{}) error

PublishExcludeMe is a short hand for Publish(tobicURI, event, true) that will not send the event to ourself.

func (*Client) SetSessionOpenCallback Uses

func (c *Client) SetSessionOpenCallback(f func(string))

SetSessionOpenCallback adds a callback function that is run when a new session begins. The callback function must accept a string argument that is the session ID.

func (*Client) Subscribe Uses

func (c *Client) Subscribe(topicURI string, f EventHandler) error

Subscribe adds a subscription at the server for events with topicURI lasting for the session or until Unsubscribe is called.

Ref: http://wamp.ws/spec#subscribe_message

func (*Client) Unsubscribe Uses

func (c *Client) Unsubscribe(topicURI string) error

Unsubscribe removes a previous subscription with topicURI at the server.

Ref: http://wamp.ws/spec#unsubscribe_message

type EventHandler Uses

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

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

type HandlerFunc Uses

type HandlerFunc func(clientID string, topicURI string, args ...interface{}) (interface{}, error)

func (HandlerFunc) HandleRPC Uses

func (f HandlerFunc) HandleRPC(clientID string, topicURI string, args ...interface{}) (interface{}, error)

type PubHandler Uses

type PubHandler func(topicURI string, event interface{}) interface{}

PubHandler is an interface that handlers for publishes should implement to get notified on a client publish with the possibility to modify the event. The event that will be published should be returned.

type RPCError Uses

type RPCError struct {
    URI         string
    Description string
    Details     interface{}
}

RPCError represents a call error and is the recommended way to return an error from a RPC handler.

func (RPCError) Error Uses

func (e RPCError) Error() string

Error returns an error description.

type RPCHandler Uses

type RPCHandler interface {
    // RPCHandler is an interface that handlers to RPC calls should implement.
    // The first parameter is the call ID, the second is the proc URI. Last comes
    // all optional arguments to the RPC call. The return can be of any type that
    // can be marshaled to JSON, or a error (preferably RPCError but any error works.)
    // NOTE: this may be broken in v2 if multiple-return is implemented
    HandleRPC(clientID string, topicURI string, args ...interface{}) (interface{}, error)
}

Using a handle func pattern so we can adapt the calls and do things like retry

type Server Uses

type Server struct {
    websocket.Server
    // contains filtered or unexported fields
}

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

func NewServer Uses

func NewServer(isDebug bool) *Server

NewServer creates a new WAMP server.

func (*Server) ConnectedClients Uses

func (t *Server) ConnectedClients() []string

ConnectedClients returns a slice of the ids of all connected clients

func (*Server) HandleWebsocket Uses

func (t *Server) HandleWebsocket(conn *websocket.Conn)

HandleWebsocket implements the go.net/websocket.Handler interface.

func (*Server) RegisterPubHandler Uses

func (t *Server) RegisterPubHandler(uri string, f PubHandler)

RegisterPubHandler adds a handler called when a client publishes to URI. The event can be modified in the handler and the returned event is what is published to the other clients.

func (*Server) RegisterRPC Uses

func (t *Server) RegisterRPC(uri string, f func(clientID string, topicURI string, args ...interface{}) (interface{}, error))

func (*Server) RegisterRPCFunc Uses

func (t *Server) RegisterRPCFunc(uri string, f RPCHandler)

RegisterRPC adds a handler for the RPC named uri.

func (*Server) RegisterSubHandler Uses

func (t *Server) RegisterSubHandler(uri string, f SubHandler)

RegisterSubHandler adds a handler called when a client subscribes to URI. The subscription can be canceled in the handler by returning false, or approved by returning true.

func (*Server) SendEvent Uses

func (t *Server) SendEvent(topic string, event interface{}, excludeMe bool, excludeList []string, eligibleList []string)

SendEvent sends an event with topic directly (not via Client.Publish())

func (*Server) SetSessionOpenCallback Uses

func (t *Server) SetSessionOpenCallback(f func(string))

SetSessionOpenCallback adds a callback function that is run when a new session begins. The callback function must accept a string argument that is the session ID.

func (*Server) SubscribedTopicUris Uses

func (t *Server) SubscribedTopicUris() []string

func (*Server) UnregisterPubHandler Uses

func (t *Server) UnregisterPubHandler(uri string)

UnregisterPubHandler removes a publish handler for the URI.

func (*Server) UnregisterRPC Uses

func (t *Server) UnregisterRPC(uri string)

UnregisterRPC removes a handler for the RPC named uri.

func (*Server) UnregisterSubHandler Uses

func (t *Server) UnregisterSubHandler(uri string)

UnregisterSubHandler removes a subscription handler for the URI.

type SubHandler Uses

type SubHandler func(clientID string, topicURI string) bool

SubHandler is an interface that handlers for subscriptions should implement to control with subscriptions are valid. A subscription is allowed by returning true or denied by returning false.

type WAMPError Uses

type WAMPError struct {
    Msg string
}

A WAMPError is returned when attempting to create a message that does not follow the WAMP protocol

func (*WAMPError) Error Uses

func (e *WAMPError) Error() string

Error implements the error interface to provide a message.

Directories

PathSynopsis
client
server

Package turnpike imports 16 packages (graph) and is imported by 4 packages. Updated 2017-03-18. Refresh now. Tools for package owners.