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 ¶
- func SetLogLevel(level logrus.Level)
- type Call
- type Client
- func (c *Client) Call(serviceMethod string, args []interface{}) (interface{}, error)
- func (c *Client) Close()
- func (c *Client) CollectionByName(name string) Collection
- func (c *Client) CollectionByNameWithDefault(name string, makeDefault func(string) Collection) Collection
- func (c *Client) Go(serviceMethod string, args []interface{}, done chan *Call) *Call
- func (c *Client) Ping()
- func (c *Client) PingPong(id string, timeout time.Duration, handler func(error))
- func (c *Client) Reconnect()
- func (c *Client) ResetStats()
- func (c *Client) Send(msg interface{}) error
- func (c *Client) Session() string
- func (c *Client) Sub(subName string, args []interface{}) error
- func (c *Client) Subscribe(subName string, args []interface{}, done chan *Call) *Call
- func (c *Client) Version() string
- type Collection
- type Connect
- type Doc
- func (d *Doc) DirForPath(path []string) (dir map[string]interface{}, key string, err error)
- func (d *Doc) GetMapForPath(path []string) (map[string]interface{}, error)
- func (d *Doc) GetStringForPath(path []string) (string, error)
- func (d *Doc) ItemForPath(path []string) (item interface{}, err error)
- func (d *Doc) MapForPath(path []string, value map[string]interface{}) error
- func (d *Doc) Split(path []string) (dir []string, file string, err error)
- func (d *Doc) StringForPath(value, path []string) error
- type KeyCache
- func (c *KeyCache) AddUpdateListener(ch chan<- map[string]interface{})
- func (c *KeyCache) Added(msg map[string]interface{})
- func (c *KeyCache) AddedBefore(msg map[string]interface{})
- func (c *KeyCache) Changed(msg map[string]interface{})
- func (c *KeyCache) FindAll() map[string]interface{}
- func (c *KeyCache) FindOne(id string) interface{}
- func (c *KeyCache) MovedBefore(msg map[string]interface{})
- func (c *KeyCache) Removed(msg map[string]interface{})
- func (c *KeyCache) Reset()
- type Message
- type Method
- type MockCache
- func (c *MockCache) AddUpdateListener(ch chan<- map[string]interface{})
- func (c *MockCache) Added(msg map[string]interface{})
- func (c *MockCache) AddedBefore(msg map[string]interface{})
- func (c *MockCache) Changed(msg map[string]interface{})
- func (c *MockCache) FindAll() map[string]interface{}
- func (c *MockCache) FindOne(id string) interface{}
- func (c *MockCache) MovedBefore(msg map[string]interface{})
- func (c *MockCache) Removed(msg map[string]interface{})
- func (c *MockCache) Reset()
- type OrderedCache
- func (c *OrderedCache) AddUpdateListener(ch chan<- map[string]interface{})
- func (c *OrderedCache) Added(msg map[string]interface{})
- func (c *OrderedCache) AddedBefore(msg map[string]interface{})
- func (c *OrderedCache) Changed(msg map[string]interface{})
- func (c *OrderedCache) FindAll() map[string]interface{}
- func (c *OrderedCache) FindOne(id string) interface{}
- func (c *OrderedCache) MovedBefore(msg map[string]interface{})
- func (c *OrderedCache) Removed(msg map[string]interface{})
- func (c *OrderedCache) Reset()
- type Ping
- type Pong
- type Sub
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetLogLevel ¶
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 ¶
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 ¶
Call invokes the named function, waits for it to complete, and returns its error status.
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 ¶
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 ¶
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 ¶
Send transmits messages to the server. The msg parameter must be json encoder compatible.
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 NewReconnect ¶
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 ¶
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 ¶
GetMapForPath locates a map[string]interface{} - json object - at a path or returns an error.
func (*Doc) GetStringForPath ¶
GetStringForPath returns a string value for the path or an error if the string was found.
func (*Doc) ItemForPath ¶
ItemForPath locates the "raw" item at the provided path, returning the item found or an error.
func (*Doc) MapForPath ¶
MapForPath sets a map[string]interface{} - json object - at a path or returns an error.
func (*Doc) Split ¶
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 ¶
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 ¶
AddUpdateListener adds a listener for changes on a collection.
func (*KeyCache) AddedBefore ¶
func (*KeyCache) MovedBefore ¶
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.
type MockCache ¶
type MockCache struct { }
MockCache implements the Collection interface but does nothing with the data.
func (*MockCache) AddUpdateListener ¶
AddUpdateListener does nothing.
func (*MockCache) AddedBefore ¶
func (*MockCache) MovedBefore ¶
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{})