Documentation ¶
Index ¶
- type Event
- type EventResponse
- type EventType
- type FactoryPlugin
- type Manager
- func (m *Manager) Autoload(prefix string, extensionpath ...string) *Manager
- func (m *Manager) Load(extname ...string) *Manager
- func (m *Manager) Publish(event EventType, obj interface{}) (*Manager, error)
- func (m *Manager) Register() *Manager
- func (m *Manager) Response(event EventType, listener ...func(p *Plugin, r *EventResponse)) *Manager
- func (m *Manager) Subscribe(b *emission.Emitter) *Manager
- type Plugin
- type PluginFactory
- type PluginHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { Name EventType `json:"name"` Data string `json:"data"` File string `json:"file"` // If Data >> 10K write content to file instead }
Event describes the event structure. Contains a Name field and a Data field which is marshalled in JSON
func NewEvent ¶
NewEvent returns a new event which can be used for publishing the obj gets automatically serialized in json.
func (Event) ResponseEventName ¶
type EventResponse ¶
type EventResponse struct { State string `json:"state"` Data string `json:"data"` Error string `json:"error"` }
EventResponse describes the event response structure It represent the JSON response from plugins
func (EventResponse) Errored ¶
func (r EventResponse) Errored() bool
Errored returns true if the response contains an error
func (EventResponse) Unmarshal ¶
func (r EventResponse) Unmarshal(i interface{}) error
Unmarshal decodes the json payload in the given parameteer
type FactoryPlugin ¶
type FactoryPlugin struct { EventType EventType PluginHandler PluginHandler }
type Manager ¶
Manager describes a set of Plugins and a set of Event types which are subscribed to a message bus
func NewManager ¶
NewManager returns a manager instance with a new bus and
func (*Manager) Autoload ¶
Autoload automatically loads plugins binaries prefixed by 'prefix' in the current path optionally takes a list of paths to look also into
func (*Manager) Load ¶
Load finds the binaries given as parameter (without path) and scan the system $PATH to retrieve those automatically
func (*Manager) Publish ¶
Publish is a wrapper around NewEvent and the Manager internal Bus publishing system It accepts optionally a list of functions that are called with the plugin result (only once)
type Plugin ¶
Plugin describes binaries to be hooked on events, with common js input, and common js output
type PluginFactory ¶
type PluginFactory map[EventType]PluginHandler
PluginFactory is a collection of handlers for a given event type. a plugin has to respond to multiple events and it always needs to return an Event response as result
func NewPluginFactory ¶
func NewPluginFactory(p ...FactoryPlugin) PluginFactory
func (PluginFactory) Add ¶
func (p PluginFactory) Add(ev EventType, ph PluginHandler)
Add associates an handler to an event type
type PluginHandler ¶
type PluginHandler func(*Event) EventResponse
PluginHandler represent a generic plugin which talks go-pluggable API It receives an event, and is always expected to give a response