turnpike

package module
v0.0.0-...-559d090 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2018 License: MIT Imports: 16 Imported by: 0

README

Turnpike Build Status Coverage Status GoDoc

Go implementation of WAMP - The Web Application Messaging Protocol

WAMP ("The Web Application Messaging Protocol") is a communication protocol that enables distributed application architectures, with application functionality spread across nodes and all application communication decoupled by messages routed via dedicated WAMP routers.

At its core, WAMP provides applications with two asynchronous messaging patterns within one unified protocol:

  • Publish & Subscribe
  • Remote Procedure Calls

This package provides router and client library implementations as well as a basic stand-alone router. The router library can be used to embed a WAMP router in another application, or to build a custom router implementation. The client library can be used to communicate with any WAMP router.

This version of Turnpike supports WAMP v2. For WAMP v1 support see the v1 branch.

Status

Turnpike v2 is still under development, but is getting close to a stable release. If you have any feedback or suggestions, please open an issue.

Installation

Library:

go get -u gopkg.in/jcelliott/turnpike.v2

Stand-alone router:

go get -u gopkg.in/jcelliott/turnpike.v2/turnpike

Client library usage

// TODO

Server library usage

main.go:

package main

import (
	"log"
	"net/http"

	"gopkg.in/jcelliott/turnpike.v2"
)

func main() {
	turnpike.Debug()
	s := turnpike.NewBasicWebsocketServer("example.realm")
	server := &http.Server{
		Handler: s,
		Addr:    ":8000",
	}
	log.Println("turnpike server starting on port 8000")
	log.Fatal(server.ListenAndServe())
}

This creates a simple WAMP router listening for websocket connections on port 8000 with a single realm configured.

You can build it like this:

go build -o router main.go

Which will create an executable in your working directory that can be run like this:

./router

Stand-alone router usage

Run the router with default settings:

$GOPATH/bin/turnpike

Router options:

Usage of turnpike:
  -port int
        port to run on (default 8000)
  -realm string
        realm name (default "realm1")

Documentation

Overview

Package turnpike implements WAMPv2 - The Web Application Messaging Protocol.

It provides router and client library implementations as well as a basic stand-alone router. The router library can be used to embed a WAMP router in another application, or to build a custom router implementation. The client library can be used to communicate with any WAMP router.

See the official WAMP documentation at http://wamp.ws for more details on the protocol.

Index

Constants

View Source
const (

	// Peer provided an incorrect URI for any URI-based attribute of WAMP message,
	// such as realm, topic or procedure.
	ErrInvalidUri = URI("wamp.error.invalid_uri")

	// A Dealer could not perform a call, since no procedure is currently
	// registered under the given URI.
	ErrNoSuchProcedure = URI("wamp.error.no_such_procedure")

	// A procedure could not be registered, since a procedure with the given URI
	// is already registered.
	ErrProcedureAlreadyExists = URI("wamp.error.procedure_already_exists")

	// A Dealer could not perform an unregister, since the given registration is
	// not active.
	ErrNoSuchRegistration = URI("wamp.error.no_such_registration")

	// A Broker could not perform an unsubscribe, since the given subscription is
	// not active.
	ErrNoSuchSubscription = URI("wamp.error.no_such_subscription")

	// A call failed, since the given argument types or values are not acceptable
	// to the called procedure - in which case the Callee may throw this error. Or
	// a Router performing payload validation checked the payload (args / kwargs)
	// of a call, call result, call error or publish, and the payload did not
	// conform - in which case the Router may throw this error.
	ErrInvalidArgument = URI("wamp.error.invalid_argument")

	// The Peer is shutting down completely - used as a GOODBYE (or ABORT) reason.
	ErrSystemShutdown = URI("wamp.error.system_shutdown")

	// The Peer wants to leave the realm - used as a GOODBYE reason.
	ErrCloseRealm = URI("wamp.error.close_realm")

	// A Peer acknowledges ending of a session - used as a GOOBYE reply reason.
	ErrGoodbyeAndOut = URI("wamp.error.goodbye_and_out")

	// A join, call, register, publish or subscribe failed, since the Peer is not
	// authorized to perform the operation.
	ErrNotAuthorized = URI("wamp.error.not_authorized")

	// A Dealer or Broker could not determine if the Peer is authorized to perform
	// a join, call, register, publish or subscribe, since the authorization
	// operation itself failed. E.g. a custom authorizer ran into an error.
	ErrAuthorizationFailed = URI("wamp.error.authorization_failed")

	// Peer wanted to join a non-existing realm (and the Router did not allow to
	// auto-create the realm)
	ErrNoSuchRealm = URI("wamp.error.no_such_realm")

	// A Peer was to be authenticated under a Role that does not (or no longer)
	// exists on the Router. For example, the Peer was successfully authenticated,
	// but the Role configured does not exists - hence there is some
	// misconfiguration in the Router.
	ErrNoSuchRole = URI("wamp.error.no_such_role")
)

Variables

This section is empty.

Functions

func Debug

func Debug()

Debug changes the log output to stderr

func DebugOff

func DebugOff()

DebugOff changes the log to a noop logger

func SetLogger

func SetLogger(l Logger)

SetLogger allows users to inject their own logger instead of the default one.

Types

type Abort

type Abort struct {
	Details map[string]interface{}
	Reason  URI
}

[ABORT, Details|dict, Reason|uri]

func (*Abort) MessageType

func (msg *Abort) MessageType() MessageType

type AuthFunc

type AuthFunc func(map[string]interface{}, map[string]interface{}) (string, map[string]interface{}, error)

AuthFunc takes the HELLO details and CHALLENGE details and returns the signature string and a details map

type Authenticate

type Authenticate struct {
	Signature string
	Extra     map[string]interface{}
}

[AUTHENTICATE, Signature|string, Extra|dict]

func (*Authenticate) MessageType

func (msg *Authenticate) MessageType() MessageType

type AuthenticationError

type AuthenticationError string

Peer was unable to authenticate

func (AuthenticationError) Error

func (e AuthenticationError) Error() string

type Authenticator

type Authenticator interface {
	// Authenticate takes the HELLO details and returns a (WELCOME) details map if the
	// authentication is successful, otherwise it returns an error
	Authenticate(details map[string]interface{}) (map[string]interface{}, error)
}

Authenticator describes a type that can handle authentication based solely on the HELLO message.

Use CRAuthenticator for more complex authentication schemes.

type Authorizer

type Authorizer interface {
	Authorize(session *Session, msg Message) (bool, error)
}

Authorizer is the interface implemented by an object that can determine whether a particular request is authorized or not.

Authorize takes the session and the message (request), and returns true if the request is authorized, otherwise false.

func NewDefaultAuthorizer

func NewDefaultAuthorizer() Authorizer

NewDefaultAuthorizer returns the default authorizer struct

type BasicMethodHandler

type BasicMethodHandler func(args []interface{}, kwargs map[string]interface{}) (result *CallResult)

BasicMethodHandler is an RPC endpoint that doesn't expect the `Details` map

type BinaryData

type BinaryData []byte

BindaryData is a byte array that can be marshalled and unmarshalled according to WAMP specifications: https://github.com/tavendo/WAMP/blob/master/spec/basic.md#binary-conversion-of-json-strings

This type *should* be used in types that will be marshalled as JSON.

func (BinaryData) MarshalJSON

func (b BinaryData) MarshalJSON() ([]byte, error)

func (*BinaryData) UnmarshalJSON

func (b *BinaryData) UnmarshalJSON(arr []byte) error

type Broker

type Broker interface {
	// Publishes a message to all Subscribers.
	Publish(*Session, *Publish)
	// Subscribes to messages on a URI.
	Subscribe(*Session, *Subscribe)
	// Unsubscribes from messages on a URI.
	Unsubscribe(*Session, *Unsubscribe)
	// Removes all subscriptions of the subscriber.
	RemoveSession(*Session)
}

Broker is the interface implemented by an object that handles routing EVENTS from Publishers to Subscribers.

func NewDefaultBroker

func NewDefaultBroker() Broker

NewDefaultBroker initializes and returns a simple broker that matches URIs to Subscribers.

type CRAuthenticator

type CRAuthenticator interface {
	// accept HELLO details and returns a challenge map (which will be sent in a CHALLENGE message)
	Challenge(details map[string]interface{}) (map[string]interface{}, error)
	// accept a challenge map (same as was generated in Challenge) and a signature string, and
	// authenticates the signature string against the challenge. Returns a details map and error.
	Authenticate(challenge map[string]interface{}, signature string) (map[string]interface{}, error)
}

CRAuthenticator describes a type that can handle challenge/response authentication.

func NewBasicTicketAuthenticator

func NewBasicTicketAuthenticator(tickets ...string) CRAuthenticator

NewBasicTicketAuthenticator creates a basic ticket authenticator from a static set of valid tickets.

This method of ticket-based authentication is insecure, but useful for bootstrapping. Do not use this in production.

type Call

type Call struct {
	Request     ID
	Options     map[string]interface{}
	Procedure   URI
	Arguments   []interface{}          `wamp:"omitempty"`
	ArgumentsKw map[string]interface{} `wamp:"omitempty"`
}

[CALL, Request|id, Options|dict, Procedure|uri] [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list] [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list, ArgumentsKw|dict]

func (*Call) MessageType

func (msg *Call) MessageType() MessageType

type CallResult

type CallResult struct {
	Args   []interface{}
	Kwargs map[string]interface{}
	Err    URI
}

CallResult represents the result of a CALL.

type Cancel

type Cancel struct {
	Request ID
	Options map[string]interface{}
}

[CANCEL, CALL.Request|id, Options|dict]

func (*Cancel) MessageType

func (msg *Cancel) MessageType() MessageType

type Challenge

type Challenge struct {
	AuthMethod string
	Extra      map[string]interface{}
}

[CHALLENGE, AuthMethod|string, Extra|dict]

func (*Challenge) MessageType

func (msg *Challenge) MessageType() MessageType

type Client

type Client struct {
	Peer
	// ReceiveTimeout is the amount of time that the client will block waiting for a response from the router.
	ReceiveTimeout time.Duration
	// Auth is a map of WAMP authmethods to functions that will handle each auth type
	Auth map[string]AuthFunc
	// ReceiveDone is notified when the client's connection to the router is lost.
	ReceiveDone chan bool
	// contains filtered or unexported fields
}

A Client routes messages to/from a WAMP router.

func NewClient

func NewClient(p Peer) *Client

NewClient takes a connected Peer and returns a new Client

func NewWebsocketClient

func NewWebsocketClient(serialization Serialization, url string, requestHeader http.Header, tlscfg *tls.Config, dial DialFunc) (*Client, error)

NewWebsocketClient creates a new websocket client connected to the specified `url` and using the specified `serialization`.

func (*Client) BasicRegister

func (c *Client) BasicRegister(procedure string, fn BasicMethodHandler) error

BasicRegister registers a BasicMethodHandler procedure with the router

func (*Client) Call

func (c *Client) Call(procedure string, options map[string]interface{}, args []interface{}, kwargs map[string]interface{}) (*Result, error)

Call calls a procedure given a URI.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the server.

func (*Client) JoinRealm

func (c *Client) JoinRealm(realm string, details map[string]interface{}) (map[string]interface{}, error)

JoinRealm joins a WAMP realm, but does not handle challenge/response authentication.

func (*Client) LeaveRealm

func (c *Client) LeaveRealm() error

LeaveRealm leaves the current realm without closing the connection to the server.

func (*Client) Publish

func (c *Client) Publish(topic string, options map[string]interface{}, args []interface{}, kwargs map[string]interface{}) error

Publish publishes an EVENT to all subscribed peers.

func (*Client) Receive

func (c *Client) Receive()

Receive handles messages from the server until this client disconnects.

This function blocks and is most commonly run in a goroutine.

func (*Client) Register

func (c *Client) Register(procedure string, fn MethodHandler, options map[string]interface{}) error

Register registers a MethodHandler procedure with the router.

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, options map[string]interface{}, fn EventHandler) error

Subscribe registers the EventHandler to be called for every message in the provided topic.

func (*Client) Unregister

func (c *Client) Unregister(procedure string) error

Unregister removes a procedure with the router

func (*Client) Unsubscribe

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

Unsubscribe removes the registered EventHandler from the topic.

type Dealer

type Dealer interface {
	// Register a procedure on an endpoint
	Register(*Session, *Register)
	// Unregister a procedure on an endpoint
	Unregister(*Session, *Unregister)
	// Call a procedure on an endpoint
	Call(*Session, *Call)
	// Return the result of a procedure call
	Yield(*Session, *Yield)
	// Handle an ERROR message from an invocation
	Error(*Session, *Error)
	// Remove a callee's registrations
	RemoveSession(*Session)
}

A Dealer routes and manages RPC calls to callees.

func NewDefaultDealer

func NewDefaultDealer() Dealer

NewDefaultDealer returns the default turnpike dealer implementation

type DialFunc

type DialFunc func(network, addr string) (net.Conn, error)

type Error

type Error struct {
	Type        MessageType
	Request     ID
	Details     map[string]interface{}
	Error       URI
	Arguments   []interface{}          `wamp:"omitempty"`
	ArgumentsKw map[string]interface{} `wamp:"omitempty"`
}

[ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri] [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list] [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict]

func (*Error) MessageType

func (msg *Error) MessageType() MessageType

type Event

type Event struct {
	Subscription ID
	Publication  ID
	Details      map[string]interface{}
	Arguments    []interface{}          `wamp:"omitempty"`
	ArgumentsKw  map[string]interface{} `wamp:"omitempty"`
}

[EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict] [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list] [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list,

PUBLISH.ArgumentsKw|dict]

func (*Event) MessageType

func (msg *Event) MessageType() MessageType

type EventHandler

type EventHandler func(args []interface{}, kwargs map[string]interface{})

EventHandler handles a publish event.

type Goodbye

type Goodbye struct {
	Details map[string]interface{}
	Reason  URI
}

[GOODBYE, Details|dict, Reason|uri]

func (*Goodbye) MessageType

func (msg *Goodbye) MessageType() MessageType

type Hello

type Hello struct {
	Realm   URI
	Details map[string]interface{}
}

[HELLO, Realm|uri, Details|dict]

func (*Hello) MessageType

func (msg *Hello) MessageType() MessageType

type ID

type ID uint64

An ID is a unique, non-negative number. Different uses may have additional restrictions.

func NewID

func NewID() ID

NewID generates a random WAMP ID.

type Interceptor

type Interceptor interface {
	Intercept(session *Session, msg *Message)
}

Interceptor is the interface implemented by an object that intercepts messages in the router to modify them somehow.

Intercept takes the session and (a pointer to) the message, and (possibly) modifies the message.

func NewDefaultInterceptor

func NewDefaultInterceptor() Interceptor

NewDefaultInterceptor returns the default interceptor, which does nothing.

type Interrupt

type Interrupt struct {
	Request ID
	Options map[string]interface{}
}

[INTERRUPT, INVOCATION.Request|id, Options|dict]

func (*Interrupt) MessageType

func (msg *Interrupt) MessageType() MessageType

type Invocation

type Invocation struct {
	Request      ID
	Registration ID
	Details      map[string]interface{}
	Arguments    []interface{}          `wamp:"omitempty"`
	ArgumentsKw  map[string]interface{} `wamp:"omitempty"`
}

[INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict] [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list] [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict]

func (*Invocation) MessageType

func (msg *Invocation) MessageType() MessageType

type JSONSerializer

type JSONSerializer struct {
}

JSONSerializer is an implementation of Serializer that handles serializing and deserializing JSON encoded payloads.

func (*JSONSerializer) Deserialize

func (s *JSONSerializer) Deserialize(data []byte) (Message, error)

Deserialize unmarshals the payload into a message.

This method does not handle binary data according to WAMP specifications automatically, but instead uses the default implementation in encoding/json. Use the BinaryData type in your structures if using binary data.

func (*JSONSerializer) Serialize

func (s *JSONSerializer) Serialize(msg Message) ([]byte, error)

Serialize marshals the payload into a message.

This method does not handle binary data according to WAMP specifications automatically, but instead uses the default implementation in encoding/json. Use the BinaryData type in your structures if using binary data.

type Logger

type Logger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger is an interface compatible with log.Logger.

type Message

type Message interface {
	MessageType() MessageType
}

Message is a generic container for a WAMP message.

func GetMessageTimeout

func GetMessageTimeout(p Peer, t time.Duration) (Message, error)

GetMessageTimeout is a convenience function to get a single message from a peer within a specified period of time

type MessagePackSerializer

type MessagePackSerializer struct {
}

MessagePackSerializer is an implementation of Serializer that handles serializing and deserializing msgpack encoded payloads.

func (*MessagePackSerializer) Deserialize

func (s *MessagePackSerializer) Deserialize(data []byte) (Message, error)

Deserialize decodes a msgpack payload into a Message.

func (*MessagePackSerializer) Serialize

func (s *MessagePackSerializer) Serialize(msg Message) ([]byte, error)

Serialize encodes a Message into a msgpack payload.

type MessageType

type MessageType int
const (
	HELLO        MessageType = 1
	WELCOME      MessageType = 2
	ABORT        MessageType = 3
	CHALLENGE    MessageType = 4
	AUTHENTICATE MessageType = 5
	GOODBYE      MessageType = 6
	ERROR        MessageType = 8

	PUBLISH   MessageType = 16 //	Tx 	Rx
	PUBLISHED MessageType = 17 //	Rx 	Tx

	SUBSCRIBE    MessageType = 32 //	Rx 	Tx
	SUBSCRIBED   MessageType = 33 //	Tx 	Rx
	UNSUBSCRIBE  MessageType = 34 //	Rx 	Tx
	UNSUBSCRIBED MessageType = 35 //	Tx 	Rx
	EVENT        MessageType = 36 //	Tx 	Rx

	CALL   MessageType = 48 //	Tx 	Rx
	CANCEL MessageType = 49 //	Tx 	Rx
	RESULT MessageType = 50 //	Rx 	Tx

	REGISTER     MessageType = 64 //	Rx 	Tx
	REGISTERED   MessageType = 65 //	Tx 	Rx
	UNREGISTER   MessageType = 66 //	Rx 	Tx
	UNREGISTERED MessageType = 67 //	Tx 	Rx
	INVOCATION   MessageType = 68 //	Tx 	Rx
	INTERRUPT    MessageType = 69 //	Tx 	Rx
	YIELD        MessageType = 70 //	Rx 	Tx
)

func (MessageType) New

func (mt MessageType) New() Message

func (MessageType) String

func (mt MessageType) String() string

type MethodHandler

type MethodHandler func(
	args []interface{}, kwargs map[string]interface{}, details map[string]interface{},
) (result *CallResult)

MethodHandler is an RPC endpoint.

type NoSuchRealmError

type NoSuchRealmError string

func (NoSuchRealmError) Error

func (e NoSuchRealmError) Error() string

type Peer

type Peer interface {
	Sender

	// Closes the peer connection and any channel returned from Receive().
	// Multiple calls to Close() will have no effect.
	Close() error

	// Receive returns a channel of messages coming from the peer.
	Receive() <-chan Message

	//AddIncomeMiddleware implements preprocess income messages
	AddIncomeMiddleware(f func(Message) (Message, error))

	//GetContext returns context
	GetContext() context.Context
}

Peer is the interface that must be implemented by all WAMP peers.

func NewWebsocketPeer

func NewWebsocketPeer(serialization Serialization, url string, requestHeader http.Header, tlscfg *tls.Config, dial DialFunc) (Peer, error)

type Publish

type Publish struct {
	Request     ID
	Options     map[string]interface{}
	Topic       URI
	Arguments   []interface{}          `wamp:"omitempty"`
	ArgumentsKw map[string]interface{} `wamp:"omitempty"`
}

[PUBLISH, Request|id, Options|dict, Topic|uri] [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list] [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict]

func (*Publish) MessageType

func (msg *Publish) MessageType() MessageType

type Published

type Published struct {
	Request     ID
	Publication ID
}

[PUBLISHED, PUBLISH.Request|id, Publication|id]

func (*Published) MessageType

func (msg *Published) MessageType() MessageType

type RPCError

type RPCError struct {
	ErrorMessage *Error
	Procedure    string
}

func (RPCError) Error

func (rpc RPCError) Error() string

type Realm

type Realm struct {
	URI URI
	Broker
	Dealer
	Authorizer
	Interceptor
	CRAuthenticators map[string]CRAuthenticator
	Authenticators   map[string]Authenticator
	// DefaultAuth      func(details map[string]interface{}) (map[string]interface{}, error)
	AuthTimeout time.Duration
	// contains filtered or unexported fields
}

A Realm is a WAMP routing and administrative domain.

Clients that have connected to a WAMP router are joined to a realm and all message delivery is handled by the realm.

func (Realm) Close

func (r Realm) Close()

Close disconnects all clients after sending a goodbye message

type RealmExistsError

type RealmExistsError string

func (RealmExistsError) Error

func (e RealmExistsError) Error() string

type Register

type Register struct {
	Request   ID
	Options   map[string]interface{}
	Procedure URI
}

[REGISTER, Request|id, Options|dict, Procedure|uri]

func (*Register) MessageType

func (msg *Register) MessageType() MessageType

type Registered

type Registered struct {
	Request      ID
	Registration ID
}

[REGISTERED, REGISTER.Request|id, Registration|id]

func (*Registered) MessageType

func (msg *Registered) MessageType() MessageType

type Result

type Result struct {
	Request     ID
	Details     map[string]interface{}
	Arguments   []interface{}          `wamp:"omitempty"`
	ArgumentsKw map[string]interface{} `wamp:"omitempty"`
}

[RESULT, CALL.Request|id, Details|dict] [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list] [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict]

func (*Result) MessageType

func (msg *Result) MessageType() MessageType

type Router

type Router interface {
	Accept(Peer) error
	Close() error
	RegisterRealm(URI, Realm) error
	GetLocalPeer(URI, map[string]interface{}) (Peer, error)
	AddSessionOpenCallback(func(*Session, string))
	AddSessionCloseCallback(func(*Session, string))
}

A Router handles new Peers and routes requests to the requested Realm.

func NewDefaultRouter

func NewDefaultRouter() Router

NewDefaultRouter creates a very basic WAMP router.

type Sender

type Sender interface {
	// Send a message to the peer
	Send(Message) error
}

A Sender can send a message to its peer.

For clients, this sends a message to the router, and for routers, this sends a message to the client.

type Serialization

type Serialization int

Serialization indicates the data serialization format used in a WAMP session

const (
	// Use JSON-encoded strings as a payload.
	JSON Serialization = iota
	// Use msgpack-encoded strings as a payload.
	MSGPACK
)

type Serializer

type Serializer interface {
	Serialize(Message) ([]byte, error)
	Deserialize([]byte) (Message, error)
}

Serializer is the interface implemented by an object that can serialize and deserialize WAMP messages

type Session

type Session struct {
	Peer
	Id      ID
	Details map[string]interface{}
	// contains filtered or unexported fields
}

Session represents an active WAMP session

func (Session) String

func (s Session) String() string

type Subscribe

type Subscribe struct {
	Request ID
	Options map[string]interface{}
	Topic   URI
}

[SUBSCRIBE, Request|id, Options|dict, Topic|uri]

func (*Subscribe) MessageType

func (msg *Subscribe) MessageType() MessageType

type Subscribed

type Subscribed struct {
	Request      ID
	Subscription ID
}

[SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id]

func (*Subscribed) MessageType

func (msg *Subscribed) MessageType() MessageType

type URI

type URI string

URIs are dot-separated identifiers, where each component *should* only contain letters, numbers or underscores.

See the documentation for specifics: https://github.com/wamp-proto/wamp-proto/blob/master/rfc/text/basic/bp_identifiers.md#uris-uris

type Unregister

type Unregister struct {
	Request      ID
	Registration ID
}

[UNREGISTER, Request|id, REGISTERED.Registration|id]

func (*Unregister) MessageType

func (msg *Unregister) MessageType() MessageType

type Unregistered

type Unregistered struct {
	Request ID
}

[UNREGISTERED, UNREGISTER.Request|id]

func (*Unregistered) MessageType

func (msg *Unregistered) MessageType() MessageType

type Unsubscribe

type Unsubscribe struct {
	Request      ID
	Subscription ID
}

[UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]

func (*Unsubscribe) MessageType

func (msg *Unsubscribe) MessageType() MessageType

type Unsubscribed

type Unsubscribed struct {
	Request ID
}

[UNSUBSCRIBED, UNSUBSCRIBE.Request|id]

func (*Unsubscribed) MessageType

func (msg *Unsubscribed) MessageType() MessageType

type WebsocketServer

type WebsocketServer struct {
	Router
	Upgrader *websocket.Upgrader

	// The serializer to use for text frames. Defaults to JSONSerializer.
	TextSerializer Serializer
	// The serializer to use for binary frames. Defaults to JSONSerializer.
	BinarySerializer Serializer
	// contains filtered or unexported fields
}

WebsocketServer handles websocket connections.

func NewBasicWebsocketServer

func NewBasicWebsocketServer(uri string) *WebsocketServer

NewBasicWebsocketServer creates a new WebsocketServer with a single basic realm

func NewWebsocketServer

func NewWebsocketServer(realms map[string]Realm) (*WebsocketServer, error)

NewWebsocketServer creates a new WebsocketServer from a map of realms

func (*WebsocketServer) GetLocalClient

func (s *WebsocketServer) GetLocalClient(realm string, details map[string]interface{}) (*Client, error)

GetLocalClient returns a client connected to the specified realm

func (*WebsocketServer) RegisterProtocol

func (s *WebsocketServer) RegisterProtocol(proto string, payloadType int, serializer Serializer) error

RegisterProtocol registers a serializer that should be used for a given protocol string and payload type.

func (*WebsocketServer) ServeHTTP

func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles a new HTTP connection.

type Welcome

type Welcome struct {
	Id      ID
	Details map[string]interface{}
}

[WELCOME, Session|id, Details|dict]

func (*Welcome) MessageType

func (msg *Welcome) MessageType() MessageType

type Yield

type Yield struct {
	Request     ID
	Options     map[string]interface{}
	Arguments   []interface{}          `wamp:"omitempty"`
	ArgumentsKw map[string]interface{} `wamp:"omitempty"`
}

[YIELD, INVOCATION.Request|id, Options|dict] [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list] [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict]

func (*Yield) MessageType

func (msg *Yield) MessageType() MessageType

Jump to

Keyboard shortcuts

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