ddp

package module
v0.0.0-...-e53df9d Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2015 License: ISC Imports: 6 Imported by: 0

README

ddp

MeteorJS DDP library for Golang

Documentation

Overview

Package ddp implements the MeteorJS DDP protocol over websockets. Fallback to longpolling is NOT supported (and is not planned on ever being supported by this library). We will try to model the library after `net/http` - right now the library is barebones and doesn't provide the pluggability of http. However, that's the goal for the package eventually.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogLevel

func SetLogLevel(level logrus.Level)

Types

type Call

type Call struct {
	ID            string        // The uuid for this method call
	ServiceMethod string        // The name of the service and method to call.
	Args          []interface{} // The argument to the function (*struct).
	Reply         interface{}   // The reply from the function (*struct).
	Error         error         // After completion, the error status.
	Done          chan *Call    // Strobes when call is complete.
	Owner         *Client       // Client that owns the method call
}

Call represents an active RPC call.

type Client

type Client struct {
	// HeartbeatInterval is the time between heartbeats to send
	HeartbeatInterval time.Duration
	// HeartbeatTimeout is the time for a heartbeat ping to timeout
	HeartbeatTimeout time.Duration
	// ReconnectInterval is the time between reconnections on bad connections
	ReconnectInterval time.Duration
	// contains filtered or unexported fields
}

Client represents a DDP client connection. The DDP client establish a DDP session and acts as a message pump for other tools.

func NewClient

func NewClient(url, origin string) (*Client, error)

NewClient creates a default client (using an internal websocket) to the provided URL using the origin for the connection. The client will automatically connect, upgrade to a websocket, and establish a DDP connection session before returning the client. The client will automatically and internally handle heartbeats and reconnects.

TBD create an option to use an external websocket (aka htt.Transport) TBD create an option to substitute heartbeat and reconnect behavior (aka http.Tranport) TBD create an option to hijack the connection (aka http.Hijacker) TBD create profiling features (aka net/http/pprof)

func (*Client) Call

func (c *Client) Call(serviceMethod string, args []interface{}) (interface{}, error)

Call invokes the named function, waits for it to complete, and returns its error status.

func (*Client) Close

func (c *Client) Close()

Close implements the io.Closer interface.

func (*Client) CollectionByName

func (c *Client) CollectionByName(name string) Collection

CollectionByName retrieves a collection by it's name.

func (*Client) CollectionByNameWithDefault

func (c *Client) CollectionByNameWithDefault(name string, makeDefault func(string) Collection) Collection

CollectionByNameWithDefault retrieves a collection by it's name, and if one did not exist defaults to the one returned by the given function.

func (*Client) Go

func (c *Client) Go(serviceMethod string, args []interface{}, done chan *Call) *Call

Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.

Go and Call are modeled after the standard `net/rpc` package versions.

func (*Client) Ping

func (c *Client) Ping()

Ping sends a heartbeat signal to the server. The Ping doesn't look for a response but may trigger the connection to reconnect if the ping timesout. This is primarily useful for reviving an unresponsive Client connection.

func (*Client) PingPong

func (c *Client) PingPong(id string, timeout time.Duration, handler func(error))

PingPong sends a heartbeat signal to the server and calls the provided function when a pong is received. An optional id can be sent to help track the responses - or an empty string can be used. It is the responsibility of the caller to respond to any errors that may occur.

func (*Client) Reconnect

func (c *Client) Reconnect()

Reconnect attempts to reconnect the client to the server on the existing DDP session.

TODO needs a reconnect backoff so we don't trash a down server TODO reconnect should not allow more reconnects while a reconnection is already in progress.

func (*Client) ResetStats

func (c *Client) ResetStats()

ResetStats resets the statistics for the client.

func (*Client) Send

func (c *Client) Send(msg interface{}) error

Send transmits messages to the server. The msg parameter must be json encoder compatible.

func (*Client) Session

func (c *Client) Session() string

Session returns the negotiated session token for the connection.

func (*Client) Sub

func (c *Client) Sub(subName string, args []interface{}) error

Sub sends a synchronous subscription request to the server.

func (*Client) Subscribe

func (c *Client) Subscribe(subName string, args []interface{}, done chan *Call) *Call

Subscribe subscribes to data updates.

func (*Client) Version

func (c *Client) Version() string

Version returns the negotiated protocol version in use by the client.

type Collection

type Collection interface {

	// FindOne queries objects and returns the first match.
	FindOne(id string) interface{}
	// FindAll returns a map of all items in the cache - this is a hack
	// until we have time to build out a real minimongo interface.
	FindAll() map[string]interface{}
	// AddUpdateListener adds a channel that receives update messages.
	AddUpdateListener(chan<- map[string]interface{})

	Added(msg map[string]interface{})
	Changed(msg map[string]interface{})
	Removed(msg map[string]interface{})
	AddedBefore(msg map[string]interface{})
	MovedBefore(msg map[string]interface{})

	// for reconnects
	Reset()
}

Collection managed cached collection data sent from the server in a livedata subscription.

It would be great to build an entire mongo compatible local store (minimongo)

func NewCollection

func NewCollection(name string) Collection

NewCollection creates a new collection - always KeyCache.

func NewMockCollection

func NewMockCollection() Collection

NewMockCollection creates an empty collection that does nothing.

type Connect

type Connect struct {
	Message
	Version string   `json:"version"`
	Support []string `json:"support"`
	Session string   `json:"session,omitempty"`
}

Connect represents a DDP connect message.

func NewConnect

func NewConnect() *Connect

NewConnect creates a new connect message

func NewReconnect

func NewReconnect(session string) *Connect

NewReconnect creates a new connect message with a session ID to resume.

type Doc

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

Doc provides hides the complexity of ejson documents.

func NewDoc

func NewDoc(in interface{}) *Doc

NewDoc creates a new document from a generic json parsed document.

func (*Doc) DirForPath

func (d *Doc) DirForPath(path []string) (dir map[string]interface{}, key string, err error)

DirForPath locates a map[string]interface{} - json object - at the directory contained in the path and returns the map and key/file name specified or an error.

func (*Doc) GetMapForPath

func (d *Doc) GetMapForPath(path []string) (map[string]interface{}, error)

GetMapForPath locates a map[string]interface{} - json object - at a path or returns an error.

func (*Doc) GetStringForPath

func (d *Doc) GetStringForPath(path []string) (string, error)

GetStringForPath returns a string value for the path or an error if the string was found.

func (*Doc) ItemForPath

func (d *Doc) ItemForPath(path []string) (item interface{}, err error)

ItemForPath locates the "raw" item at the provided path, returning the item found or an error.

func (*Doc) MapForPath

func (d *Doc) MapForPath(path []string, value map[string]interface{}) error

MapForPath sets a map[string]interface{} - json object - at a path or returns an error.

func (*Doc) Split

func (d *Doc) Split(path []string) (dir []string, file string, err error)

Split splits a path returning the parts of the path directory and the last item (key/file). An empty path results in an error.

func (*Doc) StringForPath

func (d *Doc) StringForPath(value, path []string) error

StringForPath sets a string value on the path. Returns a non-nil error if the value could not be set.

type KeyCache

type KeyCache struct {
	// The name of the collection
	Name string
	// contains filtered or unexported fields
}

KeyCache caches items keyed on unique ID.

func (*KeyCache) AddUpdateListener

func (c *KeyCache) AddUpdateListener(ch chan<- map[string]interface{})

AddUpdateListener adds a listener for changes on a collection.

func (*KeyCache) Added

func (c *KeyCache) Added(msg map[string]interface{})

func (*KeyCache) AddedBefore

func (c *KeyCache) AddedBefore(msg map[string]interface{})

func (*KeyCache) Changed

func (c *KeyCache) Changed(msg map[string]interface{})

func (*KeyCache) FindAll

func (c *KeyCache) FindAll() map[string]interface{}

FindAll returns a dump of all items in the collection

func (*KeyCache) FindOne

func (c *KeyCache) FindOne(id string) interface{}

FindOne returns the item with matching id.

func (*KeyCache) MovedBefore

func (c *KeyCache) MovedBefore(msg map[string]interface{})

func (*KeyCache) Removed

func (c *KeyCache) Removed(msg map[string]interface{})

func (*KeyCache) Reset

func (c *KeyCache) Reset()

Reset state of the cache.

type Message

type Message struct {
	Type string `json:"msg"`
	ID   string `json:"id,omitempty"`
}

Message contains the common fields that all DDP messages use.

type Method

type Method struct {
	Message
	ServiceMethod string        `json:"method"`
	Args          []interface{} `json:"params"`
}

Method is used to send a remote procedure call to the server.

func NewMethod

func NewMethod(id, serviceMethod string, args []interface{}) *Method

NewMethod creates a new method invocation object.

type MockCache

type MockCache struct {
}

MockCache implements the Collection interface but does nothing with the data.

func (*MockCache) AddUpdateListener

func (c *MockCache) AddUpdateListener(ch chan<- map[string]interface{})

AddUpdateListener does nothing.

func (*MockCache) Added

func (c *MockCache) Added(msg map[string]interface{})

func (*MockCache) AddedBefore

func (c *MockCache) AddedBefore(msg map[string]interface{})

func (*MockCache) Changed

func (c *MockCache) Changed(msg map[string]interface{})

func (*MockCache) FindAll

func (c *MockCache) FindAll() map[string]interface{}

FindAll returns a dump of all items in the collection

func (*MockCache) FindOne

func (c *MockCache) FindOne(id string) interface{}

FindOne returns the item with matching id.

func (*MockCache) MovedBefore

func (c *MockCache) MovedBefore(msg map[string]interface{})

func (*MockCache) Removed

func (c *MockCache) Removed(msg map[string]interface{})

func (*MockCache) Reset

func (c *MockCache) Reset()

Reset does nothing.

type OrderedCache

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

OrderedCache caches items based on list order. This is a placeholder, currently not implemented as the Meteor server does not transmit ordered collections over DDP yet.

func (*OrderedCache) AddUpdateListener

func (c *OrderedCache) AddUpdateListener(ch chan<- map[string]interface{})

AddUpdateListener does nothing.

func (*OrderedCache) Added

func (c *OrderedCache) Added(msg map[string]interface{})

func (*OrderedCache) AddedBefore

func (c *OrderedCache) AddedBefore(msg map[string]interface{})

func (*OrderedCache) Changed

func (c *OrderedCache) Changed(msg map[string]interface{})

func (*OrderedCache) FindAll

func (c *OrderedCache) FindAll() map[string]interface{}

FindAll returns a dump of all items in the collection

func (*OrderedCache) FindOne

func (c *OrderedCache) FindOne(id string) interface{}

FindOne returns the item with matching id.

func (*OrderedCache) MovedBefore

func (c *OrderedCache) MovedBefore(msg map[string]interface{})

func (*OrderedCache) Removed

func (c *OrderedCache) Removed(msg map[string]interface{})

func (*OrderedCache) Reset

func (c *OrderedCache) Reset()

Reset does nothing.

type Ping

type Ping Message

Ping represents a DDP ping message.

func NewPing

func NewPing(id string) *Ping

NewPing creates a new ping message with optional ID.

type Pong

type Pong Message

Pong represents a DDP pong message.

func NewPong

func NewPong(id string) *Pong

NewPong creates a new pong message with optional ID.

type Sub

type Sub struct {
	Message
	SubName string        `json:"name"`
	Args    []interface{} `json:"params"`
}

Sub is used to send a subscription request to the server.

func NewSub

func NewSub(id, subName string, args []interface{}) *Sub

NewSub creates a new sub object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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