diff options
author | Valery Piashchynski <[email protected]> | 2021-06-21 00:34:53 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-21 00:34:53 +0300 |
commit | 2ab22ac9e935efb126b51e9c3521073e6a5155a1 (patch) | |
tree | 5c6b1d4ee2aea4e6a1cc828ca1fcb2306ef9741e /plugins/broadcast | |
parent | 18c072d5dbe3ca96fe2198f323d3bf520972e80f (diff) |
- Minor tests improvenments
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/broadcast')
-rw-r--r-- | plugins/broadcast/plugin.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/plugins/broadcast/plugin.go b/plugins/broadcast/plugin.go index 04a4fb80..6ddef806 100644 --- a/plugins/broadcast/plugin.go +++ b/plugins/broadcast/plugin.go @@ -116,7 +116,7 @@ func (p *Plugin) PublishAsync(m *pubsub.Message) { }() } -func (p *Plugin) GetDriver(key string) (pubsub.SubReader, error) { +func (p *Plugin) GetDriver(key string) (pubsub.SubReader, error) { //nolint:gocognit const op = errors.Op("broadcast_plugin_get_driver") // choose a driver @@ -164,17 +164,28 @@ func (p *Plugin) GetDriver(key string) (pubsub.SubReader, error) { return nil, errors.E(op, err) } - // save the pubsub under a config key - // + // if section already exists, return new connection + if _, ok := p.publishers[configKey]; ok { + return ps, nil + } + + // if not - initialize a connection p.publishers[configKey] = ps return ps, nil + + // then try global if local does not exist case p.cfgPlugin.Has(redis): ps, err := p.constructors[redis].PSConstruct(configKey) if err != nil { return nil, errors.E(op, err) } - // save the pubsub + // if section already exists, return new connection + if _, ok := p.publishers[configKey]; ok { + return ps, nil + } + + // if not - initialize a connection p.publishers[configKey] = ps return ps, nil } |