Switching to modules, removed vendored dependencies, linting with golangci-lint.
This commit is contained in:
@@ -19,8 +19,8 @@ package telegrampusher
|
||||
|
||||
import (
|
||||
// local
|
||||
"gitlab.com/pztrn/opensaps/context"
|
||||
"gitlab.com/pztrn/opensaps/pushers/interface"
|
||||
"go.dev.pztrn.name/opensaps/context"
|
||||
pusherinterface "go.dev.pztrn.name/opensaps/pushers/interface"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -25,8 +25,8 @@ import (
|
||||
"strings"
|
||||
|
||||
// local
|
||||
"gitlab.com/pztrn/opensaps/config/struct"
|
||||
"gitlab.com/pztrn/opensaps/slack/message"
|
||||
configstruct "go.dev.pztrn.name/opensaps/config/struct"
|
||||
slackmessage "go.dev.pztrn.name/opensaps/slack/message"
|
||||
)
|
||||
|
||||
type TelegramConnection struct {
|
||||
@@ -65,6 +65,7 @@ func (tc *TelegramConnection) SendMessage(message string) {
|
||||
|
||||
// Are we should use proxy?
|
||||
httpTransport := &http.Transport{}
|
||||
|
||||
if tc.config.Proxy.Enabled {
|
||||
// Compose proxy URL.
|
||||
proxyURL := "http://"
|
||||
@@ -73,8 +74,10 @@ func (tc *TelegramConnection) SendMessage(message string) {
|
||||
if tc.config.Proxy.Password != "" {
|
||||
proxyURL += ":" + tc.config.Proxy.Password
|
||||
}
|
||||
|
||||
proxyURL += "@"
|
||||
}
|
||||
|
||||
proxyURL += tc.config.Proxy.Address
|
||||
|
||||
proxyURLParsed, err := url.Parse(proxyURL)
|
||||
@@ -86,11 +89,13 @@ func (tc *TelegramConnection) SendMessage(message string) {
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: httpTransport}
|
||||
botUrl := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", tc.config.BotID)
|
||||
c.Log.Debugln("Bot URL:", botUrl)
|
||||
response, err := client.PostForm(botUrl, msgdata)
|
||||
botURL := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", tc.config.BotID)
|
||||
|
||||
c.Log.Debugln("Bot URL:", botURL)
|
||||
|
||||
response, err := client.PostForm(botURL, msgdata)
|
||||
if err != nil {
|
||||
c.Log.Errorln("Error ocured while sending data to Telegram:", err.Error())
|
||||
c.Log.Errorln("Error occurred while sending data to Telegram:", err.Error())
|
||||
} else {
|
||||
c.Log.Debugln("Status:", response.Status)
|
||||
if response.StatusCode != 200 {
|
||||
|
@@ -9,7 +9,7 @@
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the itplied warranty of
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
@@ -19,7 +19,7 @@ package telegrampusher
|
||||
|
||||
import (
|
||||
// local
|
||||
"gitlab.com/pztrn/opensaps/slack/message"
|
||||
slackmessage "go.dev.pztrn.name/opensaps/slack/message"
|
||||
)
|
||||
|
||||
type TelegramPusher struct{}
|
||||
@@ -31,8 +31,10 @@ func (tp TelegramPusher) Initialize() {
|
||||
cfg := c.Config.GetConfig()
|
||||
for name, config := range cfg.Telegram {
|
||||
c.Log.Infof("Initializing connection: '%s'", name)
|
||||
|
||||
conn := TelegramConnection{}
|
||||
connections[name] = &conn
|
||||
|
||||
go conn.Initialize(name, config)
|
||||
}
|
||||
}
|
||||
@@ -43,6 +45,7 @@ func (tp TelegramPusher) Push(connection string, data slackmessage.SlackMessage)
|
||||
c.Log.Errorf("Connection not found: '%s'!", connection)
|
||||
return
|
||||
}
|
||||
|
||||
c.Log.Debugf("Pushing data to '%s'", connection)
|
||||
conn.ProcessMessage(data)
|
||||
}
|
||||
|
Reference in New Issue
Block a user