diff options
author | Valery Piashchynski <[email protected]> | 2021-05-29 00:24:30 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-05-29 00:24:30 +0300 |
commit | fcda08498e8f914bbd0798da898818cd5d0e4348 (patch) | |
tree | 62d88384d07997e2373f3b273ba0cb83569ebced /plugins/channel | |
parent | 8f13eb958c7eec49acba6e343edb77c6ede89f09 (diff) |
- Add new internal plugin - channel. Which used to deliver messages from
the ws plugin to the http directly
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/channel')
-rw-r--r-- | plugins/channel/interface.go | 8 | ||||
-rw-r--r-- | plugins/channel/plugin.go | 52 |
2 files changed, 60 insertions, 0 deletions
diff --git a/plugins/channel/interface.go b/plugins/channel/interface.go new file mode 100644 index 00000000..9a405e89 --- /dev/null +++ b/plugins/channel/interface.go @@ -0,0 +1,8 @@ +package channel + +// Hub used as a channel between two or more plugins +// this is not a PUBLIC plugin, API might be changed at any moment +type Hub interface { + SendCh() chan interface{} + ReceiveCh() chan interface{} +} diff --git a/plugins/channel/plugin.go b/plugins/channel/plugin.go new file mode 100644 index 00000000..8901c42e --- /dev/null +++ b/plugins/channel/plugin.go @@ -0,0 +1,52 @@ +package channel + +import ( + "sync" +) + +const ( + PluginName string = "hub" +) + +type Plugin struct { + sync.Mutex + send chan interface{} + receive chan interface{} +} + +func (p *Plugin) Init() error { + p.Lock() + defer p.Unlock() + p.send = make(chan interface{}) + p.receive = make(chan interface{}) + return nil +} + +func (p *Plugin) Serve() chan error { + return make(chan error) +} + +func (p *Plugin) Stop() error { + close(p.receive) + return nil +} + +func (p *Plugin) SendCh() chan interface{} { + p.Lock() + defer p.Unlock() + // bi-directional queue + return p.send +} + +func (p *Plugin) ReceiveCh() chan interface{} { + p.Lock() + defer p.Unlock() + // bi-directional queue + return p.receive +} + +func (p *Plugin) Available() {} + +func (p *Plugin) Name() string { + return PluginName +} |