Documentation ¶
Overview ¶
Package io - Contains network api.Emitter implementations for io types.
Index ¶
- type ConcurrentJSON
- type JSONEmitter
- func (w *JSONEmitter) Close() error
- func (w *JSONEmitter) ListenAndEmit()
- func (w *JSONEmitter) OnClose(eventHandler api.EventHandler)
- func (w *JSONEmitter) OnReceive(reqType string, reqHandler api.RequestHandler)
- func (w *JSONEmitter) OnSend(resType string, resHandler api.ResponseHandler)
- func (w *JSONEmitter) Send(resType string, data interface{}) error
- type ReadWriteJSONCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentJSON ¶
type ConcurrentJSON struct { C ReadWriteJSONCloser // contains filtered or unexported fields }
ConcurrentJSON - Wraps a ReadWriteJSONCloser with mutexes that allow multiple concurrent readers/writers.
func (*ConcurrentJSON) ReadJSON ¶
func (c *ConcurrentJSON) ReadJSON(v interface{}) error
ReadJSON - Safely read JSON.
func (*ConcurrentJSON) WriteJSON ¶
func (c *ConcurrentJSON) WriteJSON(v interface{}) error
WriteJSON - Safely write JSON.
type JSONEmitter ¶
type JSONEmitter struct {
// contains filtered or unexported fields
}
JSONEmitter - Instantiated for each incoming connection, which implements the ReadWriteJSONCloser interface. JSONEmitter implements the leaps API by allowing components to register their own request and event handlers. All incoming messages are expected to be of the JSON format:
{ "type": "<type_string>", "body": {...} }
Handlers for request types are given the unparsed JSON body of the request.
func NewJSONEmitter ¶
func NewJSONEmitter(rw ReadWriteJSONCloser) *JSONEmitter
NewJSONEmitter - Constructs a new JSONEmitter around a ReadWriteJSONCloser.
func (*JSONEmitter) Close ¶
func (w *JSONEmitter) Close() error
Close - Close the underlying network connection.
func (*JSONEmitter) ListenAndEmit ¶
func (w *JSONEmitter) ListenAndEmit()
ListenAndEmit - Begins reading to the underlying io.ReadWriteJSONCloser and emitting events accordingly.
func (*JSONEmitter) OnClose ¶
func (w *JSONEmitter) OnClose(eventHandler api.EventHandler)
OnClose - Register an event handler for a close event.
func (*JSONEmitter) OnReceive ¶
func (w *JSONEmitter) OnReceive(reqType string, reqHandler api.RequestHandler)
OnReceive - Register a handler for a particular incoming event type.
func (*JSONEmitter) OnSend ¶
func (w *JSONEmitter) OnSend(resType string, resHandler api.ResponseHandler)
OnSend - Register a handler for a particular outgoing event type.
func (*JSONEmitter) Send ¶
func (w *JSONEmitter) Send(resType string, data interface{}) error
Send - Send data to the connected client.
type ReadWriteJSONCloser ¶
type ReadWriteJSONCloser interface { ReadJSON(v interface{}) error WriteJSON(v interface{}) error Close() error }
ReadWriteJSONCloser - An interface for writing and reading JSON content.