leaps: github.com/Jeffail/leaps/lib/api Index | Files | Directories

package api

import "github.com/Jeffail/leaps/lib/api"

Package api - Contains network API implementations.

Index

Package Files

cmd_broker.go curator_session.go emitter.go global_metadata_broker.go package.go

type CMDBroker Uses

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

CMDBroker - The leaps API allows the service owner to specify a static list of available commands. The broker is responsible for providing each new client the list of commands, then listens for requests by the client to run those commands. When a command is run the broker broadcasts the output to all connected clients.

func NewCMDBroker Uses

func NewCMDBroker(
    cmds []string,
    cmdRunner CMDRunner,
    timeout time.Duration,
    logger log.Modular,
    stats metrics.Type,
) *CMDBroker

NewCMDBroker - Create a new instance of an event broker.

func (*CMDBroker) Close Uses

func (b *CMDBroker) Close(time.Duration)

Close initiates the shut down of the background cmd runner.

func (*CMDBroker) NewEmitter Uses

func (b *CMDBroker) NewEmitter(username, uuid string, e Emitter)

NewEmitter - Register a new emitter to the broker, the emitter will begin receiving globally broadcast events from other emitters.

type CMDRunner Uses

type CMDRunner interface {
    // CMDRun runs the provided command in a shell and returns the result.
    CMDRun(cmd string) (stdout, stderr []byte, err error)
}

CMDRunner is a type that executes commands, returning separate stdout/stderr results as well as an error.

type CuratorSession Uses

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

CuratorSession - An API gateway between a client and a leaps curator. This gateway is responsible for tracking a client session as it attempts to create, connect to and edit documents.

func NewCuratorSession Uses

func NewCuratorSession(
    username, uuid string,
    emitter Emitter,
    cur curator.Type,
    timeout time.Duration,
    logger log.Modular,
    stats metrics.Type,
) *CuratorSession

NewCuratorSession - Creates a curator gateway API for a user IO session that binds to events from the provided network IO emitter. Currently the API is limited to single document access, this could, however, be changed later.

type Emitter Uses

type Emitter interface {

    // OnReceive - Register a handler for a particular incoming event type.
    OnReceive(reqType string, handler RequestHandler)

    // OnSend - Register a handler for a particular outgoing event type.
    OnSend(resType string, handler ResponseHandler)

    // OnClose - Register an event handler for a close event.
    OnClose(eventHandler EventHandler)

    // Send - Send data out to the client.
    Send(resType string, body interface{}) error
}

Emitter - To be instantiated for each connected client. Allows components to implement the leaps service API by registering their request and event handlers. The emitter then handles networked traffic and brokers incoming requests to those registered components. 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. It is guaranteed that events will NOT be triggered in parallel, although they are not guaranteed to come from the same goroutine.

type EventHandler Uses

type EventHandler func()

EventHandler - Called on a connection related event (open, close, etc)

type GlobalMetadataBroker Uses

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

GlobalMetadataBroker - The leaps API defines events that are outside of the functionality of curators and binders, such as chat messages and user join/leave notifications. The GlobalMetadataBroker implements these functions by managing references to open Emitters.

func NewGlobalMetadataBroker Uses

func NewGlobalMetadataBroker(
    timeout time.Duration,
    logger log.Modular,
    stats metrics.Type,
) *GlobalMetadataBroker

NewGlobalMetadataBroker - Create a new instance of an event broker.

func (*GlobalMetadataBroker) NewEmitter Uses

func (b *GlobalMetadataBroker) NewEmitter(username, uuid string, e Emitter)

NewEmitter - Register a new emitter to the broker, the emitter will begin receiving globally broadcast events from other emitters.

type RequestHandler Uses

type RequestHandler func(body []byte) events.TypedError

RequestHandler - Called when a request has been received, receives the body of the request and returns a TypedError indicating whether the handler was successful. Errors are sent back to the client.

type ResponseHandler Uses

type ResponseHandler func(body interface{}) bool

ResponseHandler - Called when an outgoing response is about to be sent, receives the body of the response and returns a bool indicating whether the response should be sent (false == do not send).

Directories

PathSynopsis
eventsPackage events - Contains string constants and structs for API event and error types.
ioPackage io - Contains network api.Emitter implementations for io types.

Package api imports 10 packages (graph) and is imported by 1 packages. Updated 2018-02-24. Refresh now. Tools for package owners.