mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-26 07:29:24 +00:00
Make goconst linter happy
This commit is contained in:
@ -70,6 +70,10 @@ var bridgeMap = map[string]bridge.Factory{
|
||||
"zulip": bzulip.New,
|
||||
}
|
||||
|
||||
const (
|
||||
apiProtocol = "api"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flog = log.WithFields(log.Fields{"prefix": "gateway"})
|
||||
}
|
||||
@ -158,7 +162,7 @@ RECONNECT:
|
||||
func (gw *Gateway) mapChannelConfig(cfg []config.Bridge, direction string) {
|
||||
for _, br := range cfg {
|
||||
if isApi(br.Account) {
|
||||
br.Channel = "api"
|
||||
br.Channel = apiProtocol
|
||||
}
|
||||
// make sure to lowercase irc channels in config #348
|
||||
if strings.HasPrefix(br.Account, "irc.") {
|
||||
@ -191,7 +195,7 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
|
||||
var channels []config.ChannelInfo
|
||||
|
||||
// for messages received from the api check that the gateway is the specified one
|
||||
if msg.Protocol == "api" && gw.Name != msg.Gateway {
|
||||
if msg.Protocol == apiProtocol && gw.Name != msg.Gateway {
|
||||
return channels
|
||||
}
|
||||
|
||||
@ -310,7 +314,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
||||
msg.ID = gw.getDestMsgID(origmsg.ID, dest, channel)
|
||||
|
||||
// for api we need originchannel as channel
|
||||
if dest.Protocol == "api" {
|
||||
if dest.Protocol == apiProtocol {
|
||||
msg.Channel = originchannel
|
||||
}
|
||||
|
||||
@ -459,7 +463,7 @@ func (gw *Gateway) modifyMessage(msg *config.Message) {
|
||||
}
|
||||
|
||||
// messages from api have Gateway specified, don't overwrite
|
||||
if msg.Protocol != "api" {
|
||||
if msg.Protocol != apiProtocol {
|
||||
msg.Gateway = gw.Name
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,12 @@ enable=true
|
||||
channel="--333333333333"
|
||||
`)
|
||||
|
||||
const (
|
||||
ircTestAccount = "irc.zzz"
|
||||
tgTestAccount = "telegram.zzz"
|
||||
slackTestAccount = "slack.zzz"
|
||||
)
|
||||
|
||||
func maketestRouter(input []byte) *Router {
|
||||
cfg := config.NewConfigFromString(input)
|
||||
r, err := NewRouter(cfg)
|
||||
@ -248,31 +254,31 @@ func TestGetDestChannelAdvanced(t *testing.T) {
|
||||
switch gw.Name {
|
||||
case "bridge":
|
||||
if (msg.Channel == "#main" || msg.Channel == "-1111111111111" || msg.Channel == "irc") &&
|
||||
(msg.Account == "irc.zzz" || msg.Account == "telegram.zzz" || msg.Account == "slack.zzz") {
|
||||
(msg.Account == ircTestAccount || msg.Account == tgTestAccount || msg.Account == slackTestAccount) {
|
||||
hits[gw.Name]++
|
||||
switch br.Account {
|
||||
case "irc.zzz":
|
||||
case ircTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "#main",
|
||||
Account: "irc.zzz",
|
||||
Account: ircTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "#mainirc.zzz",
|
||||
SameChannel: map[string]bool{"bridge": false},
|
||||
Options: config.ChannelOptions{Key: ""},
|
||||
}}, channels)
|
||||
case "telegram.zzz":
|
||||
case tgTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "-1111111111111",
|
||||
Account: "telegram.zzz",
|
||||
Account: tgTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "-1111111111111telegram.zzz",
|
||||
SameChannel: map[string]bool{"bridge": false},
|
||||
Options: config.ChannelOptions{Key: ""},
|
||||
}}, channels)
|
||||
case "slack.zzz":
|
||||
case slackTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "irc",
|
||||
Account: "slack.zzz",
|
||||
Account: slackTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "ircslack.zzz",
|
||||
SameChannel: map[string]bool{"bridge": false},
|
||||
@ -282,22 +288,22 @@ func TestGetDestChannelAdvanced(t *testing.T) {
|
||||
}
|
||||
case "bridge2":
|
||||
if (msg.Channel == "#main-help" || msg.Channel == "--444444444444") &&
|
||||
(msg.Account == "irc.zzz" || msg.Account == "telegram.zzz") {
|
||||
(msg.Account == ircTestAccount || msg.Account == tgTestAccount) {
|
||||
hits[gw.Name]++
|
||||
switch br.Account {
|
||||
case "irc.zzz":
|
||||
case ircTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "#main-help",
|
||||
Account: "irc.zzz",
|
||||
Account: ircTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "#main-helpirc.zzz",
|
||||
SameChannel: map[string]bool{"bridge2": false},
|
||||
Options: config.ChannelOptions{Key: ""},
|
||||
}}, channels)
|
||||
case "telegram.zzz":
|
||||
case tgTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "--444444444444",
|
||||
Account: "telegram.zzz",
|
||||
Account: tgTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "--444444444444telegram.zzz",
|
||||
SameChannel: map[string]bool{"bridge2": false},
|
||||
@ -307,22 +313,22 @@ func TestGetDestChannelAdvanced(t *testing.T) {
|
||||
}
|
||||
case "bridge3":
|
||||
if (msg.Channel == "#main-telegram" || msg.Channel == "--333333333333") &&
|
||||
(msg.Account == "irc.zzz" || msg.Account == "telegram.zzz") {
|
||||
(msg.Account == ircTestAccount || msg.Account == tgTestAccount) {
|
||||
hits[gw.Name]++
|
||||
switch br.Account {
|
||||
case "irc.zzz":
|
||||
case ircTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "#main-telegram",
|
||||
Account: "irc.zzz",
|
||||
Account: ircTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "#main-telegramirc.zzz",
|
||||
SameChannel: map[string]bool{"bridge3": false},
|
||||
Options: config.ChannelOptions{Key: ""},
|
||||
}}, channels)
|
||||
case "telegram.zzz":
|
||||
case tgTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "--333333333333",
|
||||
Account: "telegram.zzz",
|
||||
Account: tgTestAccount,
|
||||
Direction: "inout",
|
||||
ID: "--333333333333telegram.zzz",
|
||||
SameChannel: map[string]bool{"bridge3": false},
|
||||
@ -337,11 +343,11 @@ func TestGetDestChannelAdvanced(t *testing.T) {
|
||||
}
|
||||
hits[gw.Name]++
|
||||
switch br.Account {
|
||||
case "irc.zzz":
|
||||
case ircTestAccount:
|
||||
assert.Len(t, channels, 2)
|
||||
assert.Contains(t, channels, config.ChannelInfo{
|
||||
Name: "#main",
|
||||
Account: "irc.zzz",
|
||||
Account: ircTestAccount,
|
||||
Direction: "out",
|
||||
ID: "#mainirc.zzz",
|
||||
SameChannel: map[string]bool{"announcements": false},
|
||||
@ -349,25 +355,25 @@ func TestGetDestChannelAdvanced(t *testing.T) {
|
||||
})
|
||||
assert.Contains(t, channels, config.ChannelInfo{
|
||||
Name: "#main-help",
|
||||
Account: "irc.zzz",
|
||||
Account: ircTestAccount,
|
||||
Direction: "out",
|
||||
ID: "#main-helpirc.zzz",
|
||||
SameChannel: map[string]bool{"announcements": false},
|
||||
Options: config.ChannelOptions{Key: ""},
|
||||
})
|
||||
case "slack.zzz":
|
||||
case slackTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "general",
|
||||
Account: "slack.zzz",
|
||||
Account: slackTestAccount,
|
||||
Direction: "out",
|
||||
ID: "generalslack.zzz",
|
||||
SameChannel: map[string]bool{"announcements": false},
|
||||
Options: config.ChannelOptions{Key: ""},
|
||||
}}, channels)
|
||||
case "telegram.zzz":
|
||||
case tgTestAccount:
|
||||
assert.Equal(t, []config.ChannelInfo{{
|
||||
Name: "--333333333333",
|
||||
Account: "telegram.zzz",
|
||||
Account: tgTestAccount,
|
||||
Direction: "out",
|
||||
ID: "--333333333333telegram.zzz",
|
||||
SameChannel: map[string]bool{"announcements": false},
|
||||
|
Reference in New Issue
Block a user