diff --git a/pkg/telegramwriter.go b/pkg/telegramwriter.go index 68e2991..a1bb6cb 100644 --- a/pkg/telegramwriter.go +++ b/pkg/telegramwriter.go @@ -12,8 +12,6 @@ type TelegramWriter struct { chatId string } -var resultChan = make(chan *http.Response) - func (tw TelegramWriter) Write(p []byte) (n int, err error) { body, err := json.Marshal(map[string]string{ @@ -27,25 +25,20 @@ func (tw TelegramWriter) Write(p []byte) (n int, err error) { url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", tw.botToken) - go asyncPost(url, body, resultChan) - - response := <-resultChan - defer func() { - if response != nil && response.Body != nil { - response.Body.Close() - } - }() + go asyncPost(url, body) return len(p), nil } -func asyncPost(url string, body []byte, rc chan *http.Response) { +func asyncPost(url string, body []byte) { response, err := http.Post(url, messageType, bytes.NewBuffer(body)) if err != nil { - rc <- response return } - rc <- response + if response.Body != nil { + response.Body.Close() + } + }