io

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package io - Contains network api.Emitter implementations for io types.

Index

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) Close

func (c *ConcurrentJSON) Close() error

Close - Close the read/writer

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.

Jump to

Keyboard shortcuts

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