diff --git a/listener.go b/listener.go index 1564955..0dfe50e 100644 --- a/listener.go +++ b/listener.go @@ -4,3 +4,21 @@ type HostingListener struct { Name string Handler func() error } + +type HostingListenerInterface interface { + GetName() string + GetHandler() func() error + Execute() error +} + +func (hl *HostingListener) GetName() string { + return hl.Name +} + +func (hl *HostingListener) GetHandler() func() error { + return hl.Handler +} + +func (hl *HostingListener) Execute() error { + return hl.Handler() +} diff --git a/plugin.go b/plugin.go index 556927c..790cdf0 100644 --- a/plugin.go +++ b/plugin.go @@ -15,5 +15,8 @@ type HostingPluginInterface interface { GetName() string GetVersion() string GetAuthor() string - RegisterListeners() []HostingListener + RegisterListener(listener HostingListener) []HostingListener + RegisterListeners(listeners []HostingListener) []HostingListener + GetListeners() []HostingListener + GetListenerByName(name string) HostingListener } diff --git a/pluginLoader.go b/pluginLoader.go new file mode 100644 index 0000000..eb2e0d5 --- /dev/null +++ b/pluginLoader.go @@ -0,0 +1,41 @@ +package Hosting_System_Plugin_Library + +func (plugin *HostingPlugin) RegisterListener(listener HostingListener) error { + plugin.Listeners = append(plugin.Listeners, listener) + return nil +} + +func (plugin *HostingPlugin) RegisterListeners(listeners []HostingListener) error { + for _, listener := range listeners { + err := plugin.RegisterListener(listener) + if err != nil { + return err + } + } + return nil +} + +func (plugin *HostingPlugin) GetListenerByName(name string) HostingListener { + for _, listener := range plugin.Listeners { + if listener.Name == name { + return listener + } + } + return HostingListener{} +} + +func (plugin *HostingPlugin) GetName() string { + return plugin.Name +} + +func (plugin *HostingPlugin) GetVersion() string { + return plugin.Version +} + +func (plugin *HostingPlugin) GetAuthor() string { + return plugin.Author +} + +func (plugin *HostingPlugin) GetListeners() []HostingListener { + return plugin.Listeners +}