Documentation ¶
Overview ¶
< GoPlug >
-------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
GoPlug is a pure Go Plugin libary project that provides flexibility, Loose Coupling and moduler approach of Building Software in/around Go. The goal of the project is to provide a simple, fast and a reliable plugin architecture that is independent of the platform.
Lifecycle ¶
GoPlug plugin lifecycle is quite simple as it consist only three state. 1. Stopped : Plugin is not yet started or stopped 2. Discovered/Installed : Plugin is discoved and ready to be started 3. Started/Loaded : Plugin is started or Loaded for serving request
Plugin Registry ¶
Each of the application creates a Plugin Registry to manage Plugins. Plugin Registry is based on plugin discovery service that provide api to search, load and unload plugin to/from registry. Auto discovery service at plugin registry could be disabled resulting plugin to be discovered at loading time.
Plugin ¶
Each plugin makes itself available for the discovery service, and while discovered it is loaded by the application. On a successful loading start() is called and on a successful uploading stop() is called
Lazy start could be enabled to make plugin loaded by explicit call to Plugin Registry rather than at discovery.
How It Works ¶
Plugins runs a different process that sould be started explicitly. Unix domain socket is used for IPC where the communication is based on HTTP request response model.
Step by Step: 1> At start of the Plugin it opens a Unix domain socket and listen for connection 2> Once it initialized it puts the .pconf file in a specific location of Plugin Discovery 3> Plugin Registry discover the .pconf and load the configuration to get the properties and UNIX sock 4> Plugin Registry initialize the Connections using UNIX sock and it loads the Plugin information 5> Http request is made as per the methods Executed over the connection
Index ¶
- Variables
- type Plugin
- type PluginConf
- type PluginImpl
- func (plugin *PluginImpl) Notify(callBack string, data []byte) error
- func (plugin *PluginImpl) Register()
- func (plugin *PluginImpl) RegisterMethod(method func([]byte) []byte)
- func (plugin *PluginImpl) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (plugin *PluginImpl) Start() error
- func (plugin *PluginImpl) Stop() error
- type PluginImplConf
- type PluginReg
- func (pluginReg *PluginReg) GetPlugin(pluginName string, pluginNamespace string) *Plugin
- func (pluginReg *PluginReg) IsDiscovered(pluginname string, namespace string) bool
- func (pluginReg *PluginReg) IsLoaded(pluginname string, namespace string) bool
- func (pluginReg *PluginReg) LoadPlugin(pluginName string, pluginNamespace string) (*Plugin, error)
- func (pluginReg *PluginReg) Stop()
- func (pluginReg *PluginReg) UnloadPlugin(plugin *Plugin) error
- func (pluginReg *PluginReg) WaitForStop()
- type PluginRegConf
Constants ¶
This section is empty.
Variables ¶
var ( // An error to indicate the plugin not discovered ConfigLoadFailed = errors.New("Configuration load failed") // An error to indicate the plugin not discovered PluginNotDiscovered = errors.New("Plugin is not Discovered") // An error to indicate the connection to plugin could not be made PluginConnFailed = errors.New("Plugin to connection failed") // An error to indicate the plugin is already loaded PluginLoaded = errors.New("Plugin is already loaded") // Conf Extension DefaultConfExt = ".pconf" // Default Interval for Discovery search in MS DefaultInterval = 1000 )
Functions ¶
This section is empty.
Types ¶
type Plugin ¶
type Plugin struct { // The name of the Plugin PluginName string // The nameSpace of the Plugin PluginNameSpace string // The URL to reach the Plugin PluginUrl string // contains filtered or unexported fields }
func (*Plugin) Execute ¶
Executes a specific plugin method by the method name. Each method takes a byte array as input
and returns a byte array as output
func (*Plugin) GetMethods ¶
Get the list of available (registered) methods for a specific plugin
func (*Plugin) RegisterCallback ¶
Register a callback that will be called on notification from the plugin
type PluginConf ¶
type PluginImpl ¶
type PluginImpl struct {
// contains filtered or unexported fields
}
The Plugin Implentaion Struct to represent a Plugin, provides all the methods to be implemented
func PluginInit ¶
func PluginInit(pluginImplConf PluginImplConf) (*PluginImpl, error)
Initialize a plugin as per the provided plugin implementation configuration.
It returns a pointer to a PluginImpl that is used to perfom different operation on the implementde plugin
func (*PluginImpl) Notify ¶
func (plugin *PluginImpl) Notify(callBack string, data []byte) error
Method to notify a callback registered by the application by the name of the callback.
User could sent input bytes for the callback. Callback doesn't return anything
func (*PluginImpl) Register ¶
func (plugin *PluginImpl) Register()
Internal Method: Used to register a handle method for the incoming request to plugin. Should not be called explicitly
func (*PluginImpl) RegisterMethod ¶
func (plugin *PluginImpl) RegisterMethod(method func([]byte) []byte)
Method to register a function for the plugin that could be invoked by the application.
Function Prototype: func ([]byte) []byte
func (*PluginImpl) ServeHTTP ¶
func (plugin *PluginImpl) ServeHTTP(res http.ResponseWriter, req *http.Request)
Internal Method: Default handler to serve all http request that comes to the plugin. Should not be called explicitly
func (*PluginImpl) Start ¶
func (plugin *PluginImpl) Start() error
Used to start the Plugin Service. It makes a plugin operable and discoverable by application
func (*PluginImpl) Stop ¶
func (plugin *PluginImpl) Stop() error
Used to stop the Plugin service. It makes the plugin hidden from the application and stops all functionalities
type PluginImplConf ¶
type PluginImplConf struct { // Plugin location path PluginLoc string // The Name of the plugin Name string // The namespace of the plugin [optional - default: nil] Namespace string // The URL to reach the plugin over http (ie unix://ExamplePlug) [optional - default: unix://<Namespace><Name>] Url string // The LazyLoad configuration [optional - default: false] LazyLoad bool // The Function that would be called on Plugin Activation Activator func([]byte) []byte // The Function that would be called on Plugin DeActivation Stopper func([]byte) []byte }
The plugin implementaion configuration. Provides all the information that are required for the GoPlug to provide an implementation of Plugin
type PluginReg ¶
type PluginReg struct { // The discoveredPlugin list DiscoveredPlugin map[string]PluginConf // The Loaded Plugin list PluginReg map[string]*Plugin // The waitgroup to wait for till PluginRegistry doesn't stop Wg *sync.WaitGroup // The Plugin search location PluginLocation string // The mutex to sync the Plugin reg access RegAccess *sync.Mutex // The flag to stop PluginRegistry Service StopFlag bool // The Conf Extension ConfExt string // To enable and disable autoDisover. For auto Loading autoDiscover // Should be enabled. Default is false AutoDiscover bool }
PluginReg should be created per types of Plugin * each PluginReg monitor a specific location
func PluginRegInit ¶
func PluginRegInit(regConf PluginRegConf) (*PluginReg, error)
Function is called to inititate the PluginRegistry as per the Plugin registry Configuration.
It initiate and return a plugin registry pointer that could be used to manage plugins. If Discovery is enabled the DiscoverService Starts
func (*PluginReg) GetPlugin ¶
Get a plugin from the Plugin registry for a specified name and namespace
func (*PluginReg) IsDiscovered ¶
Check if a plugin is discovered by the plugin registry discovery service automatically or is discover implicitly
func (*PluginReg) IsLoaded ¶
Check if a plugin is loaded and active by the plugin registry automatically or is loaded implicitly
func (*PluginReg) LoadPlugin ¶
Load the plugin to the plugin Registry explicitly when lazy load is active.
(if The discovery Process is not running, It search for the plugin and then load it to the registry)
func (*PluginReg) Stop ¶
func (pluginReg *PluginReg) Stop()
Function to stop the Plugin Registry service. It stops the discovery service
func (*PluginReg) UnloadPlugin ¶
Unload a Plugin from the plugin Registry. It invokes a stop request to the plugin.
(It doesn't remove the Plugin from Discovered Plugin List)
func (*PluginReg) WaitForStop ¶
func (pluginReg *PluginReg) WaitForStop()
Function to wait for PluginReg Discovery service to be stopped. If its not started then it return immediately
type PluginRegConf ¶
type PluginRegConf struct { // The location to search for Plugin. Default is . PluginLocation string // To enable and disable autoDisover. For auto Loading autoDiscover // Should be enabled. Default is false AutoDiscover bool // The conf Extension. Default is .conf ConfExt string }
PluginRegConf provides the configuration to create a plugin registry