Skip to content

Commit 8aa9b13

Browse files
author
Syfaro
committed
Stop returning useless http.Handler from ListenForWebhook.
1 parent 9496bb2 commit 8aa9b13

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func main() {
8585
log.Fatal(err)
8686
}
8787

88-
updates, _ := bot.ListenForWebhook("/" + bot.Token)
88+
updates := bot.ListenForWebhook("/" + bot.Token)
8989
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
9090

9191
for update := range updates {

bot.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (<-chan Update, error) {
452452
}
453453

454454
// ListenForWebhook registers a http handler for a webhook.
455-
func (bot *BotAPI) ListenForWebhook(pattern string) (<-chan Update, http.Handler) {
455+
func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update {
456456
updatesChan := make(chan Update, 100)
457457

458-
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
458+
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
459459
bytes, _ := ioutil.ReadAll(r.Body)
460460

461461
var update Update
@@ -464,9 +464,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) (<-chan Update, http.Handler
464464
updatesChan <- update
465465
})
466466

467-
http.HandleFunc(pattern, handler)
468-
469-
return updatesChan, handler
467+
return updatesChan
470468
}
471469

472470
// AnswerInlineQuery sends a response to an inline query.

bot_test.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"io/ioutil"
66
"log"
77
"net/http"
8-
"net/http/httptest"
98
"os"
10-
"strings"
119
"testing"
1210
)
1311

@@ -351,20 +349,6 @@ func TestGetUserProfilePhotos(t *testing.T) {
351349
}
352350
}
353351

354-
func TestListenForWebhook(t *testing.T) {
355-
bot, _ := getBot(t)
356-
357-
_, handler := bot.ListenForWebhook("/")
358-
359-
req, _ := http.NewRequest("GET", "", strings.NewReader("{}"))
360-
w := httptest.NewRecorder()
361-
362-
handler.ServeHTTP(w, req)
363-
if w.Code != http.StatusOK {
364-
t.Errorf("Home page didn't return %v", http.StatusOK)
365-
}
366-
}
367-
368352
func TestSetWebhookWithCert(t *testing.T) {
369353
bot, _ := getBot(t)
370354

@@ -445,7 +429,7 @@ func ExampleNewWebhook() {
445429
log.Fatal(err)
446430
}
447431

448-
updates, _ := bot.ListenForWebhook("/" + bot.Token)
432+
updates := bot.ListenForWebhook("/" + bot.Token)
449433
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
450434

451435
for update := range updates {

0 commit comments

Comments
 (0)