diff options
author | Wim <wim@42.be> | 2016-11-13 23:09:06 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-13 23:09:06 +0100 |
commit | 497633867759601d658233257447b5b86aa1b01e (patch) | |
tree | bc732d5333ddcd0343e1c2d7fd0a025c23822196 /bridge/bridge.go | |
parent | 4fb0544b0e25bf6409811fc3e574bf45efea369d (diff) | |
parent | 99d130d1ed4c389a76d4fe7f5ea8fccb78bad444 (diff) | |
download | matterbridge-msglm-497633867759601d658233257447b5b86aa1b01e.tar.gz matterbridge-msglm-497633867759601d658233257447b5b86aa1b01e.tar.bz2 matterbridge-msglm-497633867759601d658233257447b5b86aa1b01e.zip |
Merge branch 'refactor'
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r-- | bridge/bridge.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go index 3d532242..4a422c75 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -11,35 +11,50 @@ import ( "strings" ) -type Bridge interface { +type Bridger interface { Send(msg config.Message) error - Name() string Connect() error - FullOrigin() string - Origin() string - Protocol() string JoinChannel(channel string) error } -func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) Bridge { +type Bridge struct { + Config config.Protocol + Bridger + Name string + Account string + Protocol string +} + +func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Bridge { + b := new(Bridge) accInfo := strings.Split(bridge.Account, ".") protocol := accInfo[0] name := accInfo[1] + b.Name = name + b.Protocol = protocol + b.Account = bridge.Account + // override config from environment config.OverrideCfgFromEnv(cfg, protocol, name) switch protocol { case "mattermost": - return bmattermost.New(cfg.Mattermost[name], name, c) + b.Config = cfg.Mattermost[name] + b.Bridger = bmattermost.New(cfg.Mattermost[name], bridge.Account, c) case "irc": - return birc.New(cfg.IRC[name], name, c) + b.Config = cfg.IRC[name] + b.Bridger = birc.New(cfg.IRC[name], bridge.Account, c) case "gitter": - return bgitter.New(cfg.Gitter[name], name, c) + b.Config = cfg.Gitter[name] + b.Bridger = bgitter.New(cfg.Gitter[name], bridge.Account, c) case "slack": - return bslack.New(cfg.Slack[name], name, c) + b.Config = cfg.Slack[name] + b.Bridger = bslack.New(cfg.Slack[name], bridge.Account, c) case "xmpp": - return bxmpp.New(cfg.Xmpp[name], name, c) + b.Config = cfg.Xmpp[name] + b.Bridger = bxmpp.New(cfg.Xmpp[name], bridge.Account, c) case "discord": - return bdiscord.New(cfg.Discord[name], name, c) + b.Config = cfg.Discord[name] + b.Bridger = bdiscord.New(cfg.Discord[name], bridge.Account, c) } - return nil + return b } |