summaryrefslogtreecommitdiffstats
path: root/bridge/api
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-02-27 00:33:21 +0100
committerWim <wim@42.be>2018-02-27 23:22:12 +0100
commit2bac8673829516d8314c459133e85a8c0cc1959c (patch)
treeed4123232727f9c53c685b1687725206f0b02cb6 /bridge/api
parent5fbd8a3be05cdecdde515ad459b7a5d87b056956 (diff)
downloadmatterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.tar.gz
matterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.tar.bz2
matterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.zip
Refactor using factory
Diffstat (limited to 'bridge/api')
-rw-r--r--bridge/api/api.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/bridge/api/api.go b/bridge/api/api.go
index 531315a8..b4415267 100644
--- a/bridge/api/api.go
+++ b/bridge/api/api.go
@@ -2,10 +2,10 @@ package api
import (
"encoding/json"
+ "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
- log "github.com/sirupsen/logrus"
"github.com/zfjagann/golang-ring"
"net/http"
"sync"
@@ -26,14 +26,7 @@ type ApiMessage struct {
Gateway string `json:"gateway"`
}
-var flog *log.Entry
-var protocol = "api"
-
-func init() {
- flog = log.WithFields(log.Fields{"prefix": protocol})
-}
-
-func New(cfg *config.BridgeConfig) *Api {
+func New(cfg *config.BridgeConfig) bridge.Bridger {
b := &Api{BridgeConfig: cfg}
e := echo.New()
e.HideBanner = true
@@ -50,10 +43,10 @@ func New(cfg *config.BridgeConfig) *Api {
e.POST("/api/message", b.handlePostMessage)
go func() {
if b.Config.BindAddress == "" {
- flog.Fatalf("No BindAddress configured.")
+ b.Log.Fatalf("No BindAddress configured.")
}
- flog.Infof("Listening on %s", b.Config.BindAddress)
- flog.Fatal(e.Start(b.Config.BindAddress))
+ b.Log.Infof("Listening on %s", b.Config.BindAddress)
+ b.Log.Fatal(e.Start(b.Config.BindAddress))
}()
return b
}
@@ -92,7 +85,7 @@ func (b *Api) handlePostMessage(c echo.Context) error {
message.Account = b.Account
message.ID = ""
message.Timestamp = time.Now()
- flog.Debugf("Sending message from %s on %s to gateway", message.Username, "api")
+ b.Log.Debugf("Sending message from %s on %s to gateway", message.Username, "api")
b.Remote <- message
return c.JSON(http.StatusOK, message)
}