summaryrefslogtreecommitdiffstats
path: root/gateway
diff options
context:
space:
mode:
Diffstat (limited to 'gateway')
-rw-r--r--gateway/bridgemap/bridgemap.go35
-rw-r--r--gateway/gateway.go32
-rw-r--r--gateway/gateway_test.go3
-rw-r--r--gateway/router.go4
4 files changed, 41 insertions, 33 deletions
diff --git a/gateway/bridgemap/bridgemap.go b/gateway/bridgemap/bridgemap.go
new file mode 100644
index 00000000..20577dc1
--- /dev/null
+++ b/gateway/bridgemap/bridgemap.go
@@ -0,0 +1,35 @@
+package bridgemap
+
+import (
+ "github.com/42wim/matterbridge/bridge"
+ "github.com/42wim/matterbridge/bridge/api"
+ "github.com/42wim/matterbridge/bridge/discord"
+ "github.com/42wim/matterbridge/bridge/gitter"
+ "github.com/42wim/matterbridge/bridge/irc"
+ "github.com/42wim/matterbridge/bridge/matrix"
+ "github.com/42wim/matterbridge/bridge/mattermost"
+ "github.com/42wim/matterbridge/bridge/rocketchat"
+ "github.com/42wim/matterbridge/bridge/slack"
+ "github.com/42wim/matterbridge/bridge/sshchat"
+ "github.com/42wim/matterbridge/bridge/steam"
+ "github.com/42wim/matterbridge/bridge/telegram"
+ "github.com/42wim/matterbridge/bridge/xmpp"
+ "github.com/42wim/matterbridge/bridge/zulip"
+)
+
+var FullMap = map[string]bridge.Factory{
+ "api": api.New,
+ "discord": bdiscord.New,
+ "gitter": bgitter.New,
+ "irc": birc.New,
+ "mattermost": bmattermost.New,
+ "matrix": bmatrix.New,
+ "rocketchat": brocketchat.New,
+ "slack-legacy": bslack.NewLegacy,
+ "slack": bslack.New,
+ "sshchat": bsshchat.New,
+ "steam": bsteam.New,
+ "telegram": btelegram.New,
+ "xmpp": bxmpp.New,
+ "zulip": bzulip.New,
+}
diff --git a/gateway/gateway.go b/gateway/gateway.go
index 2b8bdfa9..674179fb 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -13,20 +13,7 @@ import (
"time"
"github.com/42wim/matterbridge/bridge"
- "github.com/42wim/matterbridge/bridge/api"
"github.com/42wim/matterbridge/bridge/config"
- bdiscord "github.com/42wim/matterbridge/bridge/discord"
- bgitter "github.com/42wim/matterbridge/bridge/gitter"
- birc "github.com/42wim/matterbridge/bridge/irc"
- bmatrix "github.com/42wim/matterbridge/bridge/matrix"
- bmattermost "github.com/42wim/matterbridge/bridge/mattermost"
- brocketchat "github.com/42wim/matterbridge/bridge/rocketchat"
- bslack "github.com/42wim/matterbridge/bridge/slack"
- bsshchat "github.com/42wim/matterbridge/bridge/sshchat"
- bsteam "github.com/42wim/matterbridge/bridge/steam"
- btelegram "github.com/42wim/matterbridge/bridge/telegram"
- bxmpp "github.com/42wim/matterbridge/bridge/xmpp"
- bzulip "github.com/42wim/matterbridge/bridge/zulip"
"github.com/hashicorp/golang-lru"
"github.com/peterhellberg/emojilib"
log "github.com/sirupsen/logrus"
@@ -53,23 +40,6 @@ type BrMsgID struct {
var flog *log.Entry
-var bridgeMap = map[string]bridge.Factory{
- "api": api.New,
- "discord": bdiscord.New,
- "gitter": bgitter.New,
- "irc": birc.New,
- "mattermost": bmattermost.New,
- "matrix": bmatrix.New,
- "rocketchat": brocketchat.New,
- "slack-legacy": bslack.NewLegacy,
- "slack": bslack.New,
- "sshchat": bsshchat.New,
- "steam": bsteam.New,
- "telegram": btelegram.New,
- "xmpp": bxmpp.New,
- "zulip": bzulip.New,
-}
-
const (
apiProtocol = "api"
)
@@ -114,7 +84,7 @@ func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
br.Log = log.WithFields(log.Fields{"prefix": "bridge"})
brconfig := &bridge.Config{Remote: gw.Message, Log: log.WithFields(log.Fields{"prefix": br.Protocol}), Bridge: br}
// add the actual bridger for this protocol to this bridge using the bridgeMap
- br.Bridger = bridgeMap[br.Protocol](brconfig)
+ br.Bridger = gw.Router.BridgeMap[br.Protocol](brconfig)
}
gw.mapChannelsToBridge(br)
gw.Bridges[cfg.Account] = br
diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go
index e7b77bf4..798b30c8 100644
--- a/gateway/gateway_test.go
+++ b/gateway/gateway_test.go
@@ -5,6 +5,7 @@ import (
"strconv"
"github.com/42wim/matterbridge/bridge/config"
+ "github.com/42wim/matterbridge/gateway/bridgemap"
"github.com/stretchr/testify/assert"
"testing"
@@ -160,7 +161,7 @@ const (
func maketestRouter(input []byte) *Router {
cfg := config.NewConfigFromString(input)
- r, err := NewRouter(cfg)
+ r, err := NewRouter(cfg, bridgemap.FullMap)
if err != nil {
fmt.Println(err)
}
diff --git a/gateway/router.go b/gateway/router.go
index 13e8ddd8..e4478d84 100644
--- a/gateway/router.go
+++ b/gateway/router.go
@@ -12,14 +12,16 @@ import (
type Router struct {
config.Config
+ BridgeMap map[string]bridge.Factory
Gateways map[string]*Gateway
Message chan config.Message
MattermostPlugin chan config.Message
}
-func NewRouter(cfg config.Config) (*Router, error) {
+func NewRouter(cfg config.Config, bridgeMap map[string]bridge.Factory) (*Router, error) {
r := &Router{
Config: cfg,
+ BridgeMap: bridgeMap,
Message: make(chan config.Message),
MattermostPlugin: make(chan config.Message),
Gateways: make(map[string]*Gateway),