48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package main
|
|
|
|
type PluginRegistry struct {
|
|
CorePlugin map[string]CoreInterface
|
|
HandlerPlugin map[string]HandlerInterface
|
|
}
|
|
|
|
func NewPluginRegistry() *PluginRegistry {
|
|
r := new(PluginRegistry)
|
|
r.CorePlugin = make(map[string]CoreInterface)
|
|
r.HandlerPlugin = make(map[string]HandlerInterface)
|
|
return r
|
|
}
|
|
|
|
func (r *PluginRegistry) RegisterCorePlugin(plugin CoreInterface) error {
|
|
name, e := plugin.Register()
|
|
if e != nil {
|
|
return e
|
|
}
|
|
r.CorePlugin[name] = plugin
|
|
return nil
|
|
}
|
|
|
|
func (r *PluginRegistry) RegisterHandlerPlugin(plugin HandlerInterface) error {
|
|
name, e := plugin.Register()
|
|
if e != nil {
|
|
return e
|
|
}
|
|
r.HandlerPlugin[name] = plugin
|
|
return nil
|
|
}
|
|
|
|
func (r *PluginRegistry) GetCorePlugin(name string) CoreInterface {
|
|
return r.CorePlugin[name]
|
|
}
|
|
|
|
func (r *PluginRegistry) GetHandlerPlugin(name string) HandlerInterface {
|
|
return r.HandlerPlugin[name]
|
|
}
|
|
|
|
func (r *PluginRegistry) RemoveCorePlugin(name string) {
|
|
delete(r.CorePlugin, name)
|
|
}
|
|
|
|
func (r *PluginRegistry) RemoveHandlerPlugin(name string) {
|
|
delete(r.HandlerPlugin, name)
|
|
}
|