turnpike

package module
v0.0.0-...-32920ef Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2013 License: MIT Imports: 13 Imported by: 0

README

turnpike

Go implementation of WAMP - The Websocket Application Messaging Protocol

Turnpike provides a WAMP server and client.

Examples

chat

Very simple chat server and client written in Dart. To run, first install Dart (Dart editor should work as well), then:

cd examples/dart
pub install
./build.sh
go run server.go

Open a browser (or more) to localhost:8080. Type in the textbox and hit enter.

hello

Connect to a Turnpike server with autobahn.js:

cd examples/hello
go run server.go

Open a browser to localhost:8080. You should see a message when autobahn.js connects to Turnpike.

Documentation

Overview

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

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

Index

Constants

View Source
const (
	CLIENT_CONN_TIMEOUT = 6
	CLIENT_MAX_FAILURES = 3
)
View Source
const (
	TURNPIKE_VERSION      = "0.2.0"
	TURNPIKE_SERVER_IDENT = "turnpike-" + TURNPIKE_VERSION
)
View Source
const (
	WELCOME = iota
	PREFIX
	CALL
	CALLRESULT
	CALLERROR
	SUBSCRIBE
	UNSUBSCRIBE
	PUBLISH
	EVENT
)
View Source
const PROTOCOL_VERSION = 1
View Source
const (
	WAMP_SUBPROTOCOL_ID = "wamp"
)

Variables

View Source
var (
	ErrInvalidURI          = &WAMPError{"invalid URI"}
	ErrInvalidNumArgs      = &WAMPError{"invalid number of arguments in message"}
	ErrUnsupportedProtocol = &WAMPError{"unsupported protocol"}
)

Functions

func CheckCurie

func CheckCurie(pm PrefixMap, curie string) string

convenience function that will resolve a curie and pass through a URI

func CreateCall

func CreateCall(callID, procURI string, args ...interface{}) (string, error)

Call returns a json encoded WAMP 'CALL' message as a byte slice callID must be a randomly generated string, procURI is the URI of the remote procedure to be called, followed by zero or more call arguments

func CreateCallError

func CreateCallError(callID, errorURI, errorDesc string, errorDetails ...interface{}) (string, error)

CallError returns a json encoded WAMP 'CALLERROR' message as a byte slice callID is the randomly generated string provided by the client, errorURI is a URI identifying the error, errorDesc is a human-readable description of the error (for developers), errorDetails, if present, is a non-nil object

func CreateCallResult

func CreateCallResult(callID string, result interface{}) (string, error)

CallResult returns a json encoded WAMP 'CALLRESULT' message as a byte slice callID is the randomly generated string provided by the client

func CreateEvent

func CreateEvent(topicURI string, event interface{}) (string, error)

Event returns a json encoded WAMP 'EVENT' message as a byte slice event can be nil, a simple json type, or a complex json type

func CreatePrefix

func CreatePrefix(prefix, URI string) (string, error)

Prefix returns a json encoded WAMP 'PREFIX' message as a byte slice

func CreatePublish

func CreatePublish(topicURI string, event interface{}, opts ...interface{}) (string, error)

Publish returns a json encoded WAMP 'PUBLISH' message as a byte slice arguments must be given in one of the following formats: [ topicURI, event ] [ topicURI, event, excludeMe ] [ topicURI, event, exclude ] [ topicURI, event, exclude, eligible ] event can be nil, a simple json type, or a complex json type

func CreateSubscribe

func CreateSubscribe(topicURI string) (string, error)

Subscribe returns a json encoded WAMP 'SUBSCRIBE' message as a byte slice topicURI is the topic that the client wants to subscribe to

func CreateUnsubscribe

func CreateUnsubscribe(topicURI string) (string, error)

Unsubscribe returns a json encoded WAMP 'UNSUBSCRIBE' message as a byte slice topicURI is the topic that the client wants to unsubscribe from

func CreateWelcome

func CreateWelcome(sessionId, serverIdent string) (string, error)

Welcome returns a json encoded WAMP 'WELCOME' message as a byte slice sessionId is a randomly generated string provided by the server, serverIdent is a string that identifies the WAMP server

func HandleWebsocket

func HandleWebsocket(t Handler) func(*websocket.Conn)

HandleWebsocket is a Go1.0 shim for method values

func ParseType

func ParseType(msg string) int

func SetLogger

func SetLogger(newLog lumber.Logger)

Set the logger to an externally provided one

func TypeString

func TypeString(typ int) string

Types

type CallErrorMsg

type CallErrorMsg struct {
	CallID       string
	ErrorURI     string
	ErrorDesc    string
	ErrorDetails interface{}
}

CALLERROR

func (*CallErrorMsg) UnmarshalJSON

func (msg *CallErrorMsg) UnmarshalJSON(jsonData []byte) error

type CallMsg

type CallMsg struct {
	CallID   string
	ProcURI  string
	CallArgs []interface{}
}

CALL

func (*CallMsg) UnmarshalJSON

func (msg *CallMsg) UnmarshalJSON(jsonData []byte) error

type CallResultMsg

type CallResultMsg struct {
	CallID string
	Result interface{}
}

CALLRESULT

func (*CallResultMsg) UnmarshalJSON

func (msg *CallResultMsg) UnmarshalJSON(jsonData []byte) error

type Client

type Client struct {
	SessionId       string
	ProtocolVersion int
	ServerIdent     string
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) Call

func (c *Client) Call(callID, procURI string, args ...interface{}) error

func (*Client) Connect

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

func (*Client) Listen

func (c *Client) Listen()

func (*Client) Prefix

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

func (*Client) Publish

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

func (*Client) PublishExcludeMe

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

func (*Client) ReceiveWelcome

func (c *Client) ReceiveWelcome() error

func (*Client) Send

func (c *Client) Send()

func (*Client) Subscribe

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

func (*Client) Unsubscribe

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

type EventMsg

type EventMsg struct {
	TopicURI string
	Event    interface{}
}

EVENT

func (*EventMsg) UnmarshalJSON

func (msg *EventMsg) UnmarshalJSON(jsonData []byte) error

type Handler

type Handler interface {
	HandleWebsocket(*websocket.Conn)
}

type PrefixMap

type PrefixMap map[string]string

func (PrefixMap) RegisterPrefix

func (pm PrefixMap) RegisterPrefix(prefix, URI string) error

func (PrefixMap) ResolveCurie

func (pm PrefixMap) ResolveCurie(curie string) (string, error)

returns the full URI that the curie represents

type PrefixMsg

type PrefixMsg struct {
	Prefix string
	URI    string
}

PREFIX

func (*PrefixMsg) UnmarshalJSON

func (msg *PrefixMsg) UnmarshalJSON(jsonData []byte) error

type PublishMsg

type PublishMsg struct {
	TopicURI     string
	Event        interface{}
	ExcludeMe    bool
	ExcludeList  []string
	EligibleList []string
}

PUBLISH

func (*PublishMsg) UnmarshalJSON

func (msg *PublishMsg) UnmarshalJSON(jsonData []byte) error

type RPCError

type RPCError interface {
	error
	URI() string
	Description() string
	Details() interface{}
}

type RPCHandler

type RPCHandler func(string, string, ...interface{}) (interface{}, error)

this may be broken in v2 if multiple-return is implemented

type Server

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

func NewServer

func NewServer() *Server

func (*Server) HandleWebsocket

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

func (*Server) RegisterConnListener

func (t *Server) RegisterConnListener(listener func(bool, string, *websocket.Conn))

func (*Server) RegisterRPC

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

func (*Server) SendEvent

func (t *Server) SendEvent(topic string, event interface{})

func (*Server) UnregisterRPC

func (t *Server) UnregisterRPC(uri string)

type SubscribeMsg

type SubscribeMsg struct {
	TopicURI string
}

SUBSCRIBE

func (*SubscribeMsg) UnmarshalJSON

func (msg *SubscribeMsg) UnmarshalJSON(jsonData []byte) error

type UnsubscribeMsg

type UnsubscribeMsg struct {
	TopicURI string
}

UNSUBSCRIBE

func (*UnsubscribeMsg) UnmarshalJSON

func (msg *UnsubscribeMsg) UnmarshalJSON(jsonData []byte) error

type WAMPError

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

func (e *WAMPError) Error() string

type WelcomeMsg

type WelcomeMsg struct {
	SessionId       string
	ProtocolVersion int
	ServerIdent     string
}

WELCOME

func (*WelcomeMsg) UnmarshalJSON

func (msg *WelcomeMsg) UnmarshalJSON(jsonData []byte) error

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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