Documentation ¶
Overview ¶
Package plugins provides support for creating plugin-based applications.
Following workflow is supposed:
- main application creates RPC Host service;
- plugin starts and connects to the RPC Host: 2.1) plugin informs RPC Host about service, provided by that plugin and requests port to serve on; 2.2) RPC Host checks if such service is not provided by other connected plugin and generates port for plugin to serve on; 2.3) plugin starts RPC server on port, provided by RPC Host, and informs RPC Host about it; 2.4) RPC Host registers plugin service;
- when plugin terminates, it informs RPC Host; RPC Host unregisters plugin service;
- when RPC Host terminates, it informs all connected plugins; plugins terminates;
- when main application need to invoke some service method, RPC Host is used for dispatch it;
For handling remote calls net/rpc package usage is supposed. A plugin must register object(s) that will be used for handling remote calls.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrServiceAlreadyRegistered = errors.New("service is already registered")
ErrServiceAlreadyRegistered throws when trying to register already registered service
var ErrServiceNotRegistered = errors.New("service is not registered")
ErrServiceNotRegistered returns when trying to access non-registered service
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host interface { Addr() net.Addr Serve() Services() []string OnStop(func()) Logger() *log.Logger OnConnectPlugin(f PluginNotifyFunc) OnDisconnectPlugin(f PluginNotifyFunc) Call(serviceName string, serviceMethod string, args interface{}, reply interface{}) error }
A Host is a manager that plugins connects to. Host uses connected plugins for handling main application calls.
type Options ¶
type Options struct { Address string // TCP or unix socket address for serving connection or connecting to the remote server Log *log.Logger // a object for logging operations }
Options for RPC client/server.
type Plugin ¶
type Plugin interface { Serve() Stop() Call(serviceMethod string, args interface{}, reply interface{}) error Logger() *log.Logger OnServe(func()) OnStop(func()) }
Plugin is used for serving requests from main application.
type PluginInfo ¶
type PluginInfo struct { Name string // Human-readable name of plugin ServiceName string // Name of service provided by plugin Address string // Address plugin serves on }
PluginInfo describes a plugin.
type PluginNotifyFunc ¶
type PluginNotifyFunc func(PluginInfo)
PluginNotifyFunc is a callback function to receive notifications
type RPCHost ¶
type RPCHost struct {
// contains filtered or unexported fields
}
RPCHost implements Host RPC service. Handles plugins requests.
func (*RPCHost) ConnectPlugin ¶
func (rh *RPCHost) ConnectPlugin(info *PluginInfo, _ *int) error
ConnectPlugin handles plugin connection to host.
func (*RPCHost) DisconnectPlugin ¶
func (rh *RPCHost) DisconnectPlugin(info *PluginInfo, _ *int) error
DisconnectPlugin handles plugin disconnection from host.
func (*RPCHost) GetListenAddr ¶
func (rh *RPCHost) GetListenAddr(info *PluginInfo, listenAddr *string) error
GetListenAddr generates port for plugin to serve on.