summaryrefslogtreecommitdiffstats
path: root/bridge/slack/helpers.go
diff options
context:
space:
mode:
authorPatrick Connolly <patrick.c.connolly@gmail.com>2018-11-28 18:04:26 +0800
committerWim <wim@42.be>2018-11-28 11:04:26 +0100
commitfc5e3a672862e53192dadfd9689dad766772aeea (patch)
tree834a256bcb280e3ceaa07bee52fb5a6140f77c5e /bridge/slack/helpers.go
parent57fbd3c723d293b4181c166fe03d0dc9ea4d4e35 (diff)
downloadmatterbridge-msglm-fc5e3a672862e53192dadfd9689dad766772aeea.tar.gz
matterbridge-msglm-fc5e3a672862e53192dadfd9689dad766772aeea.tar.bz2
matterbridge-msglm-fc5e3a672862e53192dadfd9689dad766772aeea.zip
Create getChannelsByX functions to make codeclimate happy (slack) (#610)
Diffstat (limited to 'bridge/slack/helpers.go')
-rw-r--r--bridge/slack/helpers.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/bridge/slack/helpers.go b/bridge/slack/helpers.go
index 39fbcea7..b0af50f5 100644
--- a/bridge/slack/helpers.go
+++ b/bridge/slack/helpers.go
@@ -44,23 +44,21 @@ func (b *Bslack) getChannel(channel string) (*slack.Channel, error) {
}
func (b *Bslack) getChannelByName(name string) (*slack.Channel, error) {
- b.channelsMutex.RLock()
- defer b.channelsMutex.RUnlock()
-
- if channel, ok := b.channelsByName[name]; ok {
- return channel, nil
- }
- return nil, fmt.Errorf("%s: channel %s not found", b.Account, name)
+ return b.getChannelBy(name, b.channelsByName)
}
func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
+ return b.getChannelBy(ID, b.channelsByID)
+}
+
+func (b *Bslack) getChannelBy(lookupKey string, lookupMap map[string]*slack.Channel) (*slack.Channel, error) {
b.channelsMutex.RLock()
defer b.channelsMutex.RUnlock()
- if channel, ok := b.channelsByID[ID]; ok {
+ if channel, ok := lookupMap[lookupKey]; ok {
return channel, nil
}
- return nil, fmt.Errorf("%s: channel %s not found", b.Account, ID)
+ return nil, fmt.Errorf("%s: channel %s not found", b.Account, lookupKey)
}
const minimumRefreshInterval = 10 * time.Second