diff options
author | Wim <wim@42.be> | 2016-11-13 23:06:37 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-13 23:06:37 +0100 |
commit | 99d130d1ed4c389a76d4fe7f5ea8fccb78bad444 (patch) | |
tree | 8799742a6713d28050f5af14ba8d2b1d62cd766a /bridge/bridge.go | |
parent | 14830d9f1c4e9435ee7a15e0839876ad1f4d1a9f (diff) | |
download | matterbridge-msglm-99d130d1ed4c389a76d4fe7f5ea8fccb78bad444.tar.gz matterbridge-msglm-99d130d1ed4c389a76d4fe7f5ea8fccb78bad444.tar.bz2 matterbridge-msglm-99d130d1ed4c389a76d4fe7f5ea8fccb78bad444.zip |
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 } |