4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 06:19:23 +00:00

Refactor and add MediaDownloadSize to General

This commit is contained in:
Wim
2017-12-19 23:15:03 +01:00
parent 4a4a29c9f6
commit 265457b451
14 changed files with 80 additions and 131 deletions

View File

@ -13,11 +13,9 @@ import (
)
type Api struct {
Config *config.Protocol
Remote chan config.Message
Account string
Messages ring.Ring
sync.RWMutex
*config.BridgeConfig
}
type ApiMessage struct {
@ -35,14 +33,11 @@ func init() {
flog = log.WithFields(log.Fields{"module": protocol})
}
func New(cfg config.Protocol, account string, c chan config.Message) *Api {
b := &Api{}
func New(cfg *config.BridgeConfig) *Api {
b := &Api{BridgeConfig: cfg}
e := echo.New()
b.Messages = ring.Ring{}
b.Messages.SetCapacity(cfg.Buffer)
b.Config = &cfg
b.Account = account
b.Remote = c
b.Messages.SetCapacity(b.Config.Buffer)
if b.Config.Token != "" {
e.Use(middleware.KeyAuth(func(key string, c echo.Context) (bool, error) {
return key == b.Config.Token, nil
@ -52,7 +47,7 @@ func New(cfg config.Protocol, account string, c chan config.Message) *Api {
e.GET("/api/stream", b.handleStream)
e.POST("/api/message", b.handlePostMessage)
go func() {
flog.Fatal(e.Start(cfg.BindAddress))
flog.Fatal(e.Start(b.Config.BindAddress))
}()
return b
}