Documentation ¶
Overview ¶
Package pingo implements the basics for creating and running subprocesses as plugins. The subprocesses will communicate via either TCP or Unix socket to implement an interface that mimics the standard RPC package.
Index ¶
- func Register(obj interface{})
- func Run() error
- type DefaultErrorHandler
- type ErrConnectionFailed
- type ErrHttpServe
- type ErrInvalidMessage
- type ErrRegistrationTimeout
- type ErrorHandler
- type PingoRpc
- type Plugin
- func (p *Plugin) Call(name string, args interface{}, resp interface{}) error
- func (p *Plugin) Objects() ([]string, error)
- func (p *Plugin) SetErrorHandler(h ErrorHandler)
- func (p *Plugin) SetSocketDirectory(dir string)
- func (p *Plugin) SetTimeout(t time.Duration)
- func (p *Plugin) Start()
- func (p *Plugin) Stop()
- func (p *Plugin) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultErrorHandler ¶
type DefaultErrorHandler struct{}
Default error handler implementation. Uses the default logging facility from the Go standard library.
func NewDefaultErrorHandler ¶
func NewDefaultErrorHandler() *DefaultErrorHandler
Constructor for default error handler.
func (*DefaultErrorHandler) Error ¶
func (e *DefaultErrorHandler) Error(err error)
Log via default standard library facility prepending the "error: " string.
func (*DefaultErrorHandler) Print ¶
func (e *DefaultErrorHandler) Print(s interface{})
Log via default standard library facility.
type ErrConnectionFailed ¶
type ErrConnectionFailed error
Error reported when connection to the external plugin has failed.
type ErrHttpServe ¶
type ErrHttpServe error
Error reported when the external plugin cannot start listening for calls.
type ErrInvalidMessage ¶
type ErrInvalidMessage error
Error reported when an invalid message is printed by the external plugin.
type ErrRegistrationTimeout ¶
type ErrRegistrationTimeout error
Error reported when the plugin fails to register before the registration timeout expires.
type ErrorHandler ¶
type ErrorHandler interface { // Error is called whenever a non-fatal error occurs in the plugin subprocess. Error(error) // Print is called for each line of output received from the plugin subprocess. Print(interface{}) }
ErrorHandler is the interface used by Plugin to report non-fatal errors and any other output from the plugin.
A default implementation is provided and used if none is specified on plugin creation.
type PingoRpc ¶
type PingoRpc struct{}
Internal object for plugin control
func NewPingoRpc ¶
func NewPingoRpc() *PingoRpc
Default constructor for interal object. Do not call manually.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Represents a plugin. After being created the plugin is not started or ready to run.
Additional configuration (ErrorHandler and Timeout) can be set after initialization.
Use Start() to make the plugin available.
func NewPlugin ¶
NewPlugin create a new plugin ready to be started, or returns an error if the initial setup fails.
The first argument specifies the protocol. It can be either set to "unix" for communication on an ephemeral local socket, or "tcp" for network communication on the local host (using a random unprivileged port.)
This constructor will panic if the proto argument is neither "unix" nor "tcp".
The path to the plugin executable should be absolute. Any path accepted by the "exec" package in the standard library is accepted and the same rules for execution are applied.
Optionally some parameters might be passed to the plugin executable.
func (*Plugin) Call ¶
Call performs an RPC call to the plugin. Prior to calling Call, the plugin must have been initialized by calling Start.
Call will hang until a plugin has been initialized; it will return any error that happens either when performing the call or during plugin initialization via Start.
Please refer to the "rpc" package from the standard library for more information on the semantics of this function.
func (*Plugin) Objects ¶
Objects returns a list of the exported objects from the plugin. Exported objects used internally are not reported.
Like Call, Objects returns any error happened on initialization if called after Start.
func (*Plugin) SetErrorHandler ¶
func (p *Plugin) SetErrorHandler(h ErrorHandler)
Set the error (and output) handler implementation. Use this to set a custom implementation. By default, standard logging is used. See ErrorHandler.
Panics if called after Start.
func (*Plugin) SetSocketDirectory ¶
func (*Plugin) SetTimeout ¶
Set the maximum time a plugin is allowed to start up and to shut down. Empty timeout (zero) is not allowed, default will be used.
Default is two seconds.
Panics if called after Start.
func (*Plugin) Start ¶
func (p *Plugin) Start()
Start will execute the plugin as a subprocess. Start will return immediately. Any first call to the plugin will reveal eventual errors occurred at initialization.
Calls subsequent to Start will hang until the plugin has been properly initialized.