From 2bac8673829516d8314c459133e85a8c0cc1959c Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 27 Feb 2018 00:33:21 +0100 Subject: Refactor using factory --- bridge/gitter/gitter.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'bridge/gitter') diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go index 69af8d2c..0cd8e520 100644 --- a/bridge/gitter/gitter.go +++ b/bridge/gitter/gitter.go @@ -3,9 +3,9 @@ package bgitter import ( "fmt" "github.com/42wim/go-gitter" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" - log "github.com/sirupsen/logrus" "strings" ) @@ -17,20 +17,13 @@ type Bgitter struct { *config.BridgeConfig } -var flog *log.Entry -var protocol = "gitter" - -func init() { - flog = log.WithFields(log.Fields{"prefix": protocol}) -} - -func New(cfg *config.BridgeConfig) *Bgitter { +func New(cfg *config.BridgeConfig) bridge.Bridger { return &Bgitter{BridgeConfig: cfg} } func (b *Bgitter) Connect() error { var err error - flog.Info("Connecting") + b.Log.Info("Connecting") b.c = gitter.New(b.Config.Token) b.User, err = b.c.GetUser() if err != nil { @@ -40,7 +33,7 @@ func (b *Bgitter) Connect() error { if err != nil { return err } - flog.Info("Connection succeeded") + b.Log.Info("Connection succeeded") return nil } @@ -78,7 +71,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error { case *gitter.MessageReceived: // ignore message sent from ourselves if ev.Message.From.ID != b.User.ID { - flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account) + b.Log.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account) rmsg := config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room, Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID, ID: ev.Message.ID} @@ -86,11 +79,11 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error { rmsg.Event = config.EVENT_USER_ACTION rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1) } - flog.Debugf("Message is %#v", rmsg) + b.Log.Debugf("Message is %#v", rmsg) b.Remote <- rmsg } case *gitter.GitterConnectionClosed: - flog.Errorf("connection with gitter closed for room %s", room) + b.Log.Errorf("connection with gitter closed for room %s", room) } } }(stream, room.URI) @@ -98,10 +91,10 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error { } func (b *Bgitter) Send(msg config.Message) (string, error) { - flog.Debugf("Receiving %#v", msg) + b.Log.Debugf("Receiving %#v", msg) roomID := b.getRoomID(msg.Channel) if roomID == "" { - flog.Errorf("Could not find roomID for %v", msg.Channel) + b.Log.Errorf("Could not find roomID for %v", msg.Channel) return "", nil } @@ -130,7 +123,7 @@ func (b *Bgitter) Send(msg config.Message) (string, error) { // Edit message if msg.ID != "" { - flog.Debugf("updating message with id %s", msg.ID) + b.Log.Debugf("updating message with id %s", msg.ID) _, err := b.c.UpdateMessage(roomID, msg.ID, msg.Username+msg.Text) if err != nil { return "", err -- cgit v1.2.3