diff options
author | Wim <wim@42.be> | 2016-09-18 19:21:15 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-09-18 19:21:15 +0200 |
commit | 7baf386edea4c71919b257d99ca7f7e07897c412 (patch) | |
tree | 5a6f7f0f506c3ab2d15d91548b1d0479bb8fb1ba /bridge/config/config.go | |
parent | 6e410b096ef15e976f6a2d28f3412fe9e457f95a (diff) | |
download | matterbridge-msglm-7baf386edea4c71919b257d99ca7f7e07897c412.tar.gz matterbridge-msglm-7baf386edea4c71919b257d99ca7f7e07897c412.tar.bz2 matterbridge-msglm-7baf386edea4c71919b257d99ca7f7e07897c412.zip |
Refactor for more flexibility
* Move from gcfg to toml configuration because gcfg was too restrictive
* Implemented gateway which has support multiple in and out bridges.
* Allow for bridging the same bridges, which means eg you can now bridge between multiple mattermosts.
* Support multiple gateways
Diffstat (limited to 'bridge/config/config.go')
-rw-r--r-- | bridge/config/config.go | 144 |
1 files changed, 55 insertions, 89 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go index 48574e28..ad8a523e 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -1,107 +1,73 @@ package config import ( - "gopkg.in/gcfg.v1" - "io/ioutil" + "github.com/BurntSushi/toml" "log" ) type Message struct { - Text string - Channel string - Username string - Origin string + Text string + Channel string + Username string + Origin string + FullOrigin string + Protocol string +} + +type Protocol struct { + BindAddress string // mattermost, slack + IconURL string // mattermost, slack + IgnoreNicks string // all protocols + Jid string // xmpp + Login string // mattermost + Muc string // xmpp + Name string // all protocols + Nick string // all protocols + NickFormatter string // mattermost, slack + NickServNick string // IRC + NickServPassword string // IRC + NicksPerRow int // mattermost, slack + NoTLS bool // mattermost + Password string // IRC,mattermost,XMPP + PrefixMessagesWithNick bool // mattemost, slack + Protocol string //all protocols + RemoteNickFormat string // all protocols + Server string // IRC,mattermost,XMPP + ShowJoinPart bool // all protocols + SkipTLSVerify bool // IRC, mattermost + Team string // mattermost + Token string // gitter, slack + URL string // mattermost, slack + UseAPI bool // mattermost, slack + UseSASL bool // IRC + UseTLS bool // IRC +} + +type Bridge struct { + Account string + Channel string +} + +type Gateway struct { + Name string + Enable bool + In []Bridge + Out []Bridge } type Config struct { - IRC struct { - UseTLS bool - UseSASL bool - SkipTLSVerify bool - Server string - Nick string - Password string - Channel string - NickServNick string - NickServPassword string - RemoteNickFormat string - IgnoreNicks string - Enable bool - } - Gitter struct { - Enable bool - IgnoreNicks string - Nick string - RemoteNickFormat string - Token string - } - Mattermost struct { - URL string - ShowJoinPart bool - IconURL string - SkipTLSVerify bool - BindAddress string - Channel string - PrefixMessagesWithNick bool - NicksPerRow int - NickFormatter string - Server string - Team string - Login string - Password string - RemoteNickFormat string - IgnoreNicks string - NoTLS bool - Enable bool - } - Slack struct { - BindAddress string - Enable bool - IconURL string - IgnoreNicks string - NickFormatter string - NicksPerRow int - PrefixMessagesWithNick bool - RemoteNickFormat string - Token string - URL string - UseAPI bool - } - Xmpp struct { - IgnoreNicks string - Jid string - Password string - Server string - Muc string - Nick string - RemoteNickFormat string - Enable bool - } - Channel map[string]*struct { - IRC string - Mattermost string - Xmpp string - Gitter string - Slack string - } - General struct { - GiphyAPIKey string - Xmpp bool - Irc bool - Mattermost bool - Plus bool - } + IRC map[string]Protocol + Mattermost map[string]Protocol + Slack map[string]Protocol + Gitter map[string]Protocol + Xmpp map[string]Protocol + Gateway []Gateway } func NewConfig(cfgfile string) *Config { var cfg Config - content, err := ioutil.ReadFile(cfgfile) - if err != nil { + if _, err := toml.DecodeFile("matterbridge.toml", &cfg); err != nil { log.Fatal(err) } - err = gcfg.ReadStringInto(&cfg, string(content)) - if err != nil { - log.Fatal("Failed to parse "+cfgfile+":", err) - } return &cfg } |