From 99d130d1ed4c389a76d4fe7f5ea8fccb78bad444 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 13 Nov 2016 23:06:37 +0100 Subject: Refactor --- bridge/bridge.go | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'bridge/bridge.go') 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 } -- cgit v1.2.3