From 80e30d7c192be106dd6c5c3777fdf3705f3a3b4a Mon Sep 17 00:00:00 2001 From: Syfaro Date: Sun, 3 Jan 2016 23:05:36 -0600 Subject: [PATCH] Stop returning useless http.Handler from ListenForWebhook. --- README.md | 2 +- bot.go | 8 +++----- bot_test.go | 18 +----------------- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0520f27..9ca6f6d 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ func main() { log.Fatal(err) } - updates, _ := bot.ListenForWebhook("/" + bot.Token) + updates := bot.ListenForWebhook("/" + bot.Token) go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) for update := range updates { diff --git a/bot.go b/bot.go index 4a02e68..e924d4b 100644 --- a/bot.go +++ b/bot.go @@ -452,10 +452,10 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (<-chan Update, error) { } // ListenForWebhook registers a http handler for a webhook. -func (bot *BotAPI) ListenForWebhook(pattern string) (<-chan Update, http.Handler) { +func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update { updatesChan := make(chan Update, 100) - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { bytes, _ := ioutil.ReadAll(r.Body) var update Update @@ -464,9 +464,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) (<-chan Update, http.Handler updatesChan <- update }) - http.HandleFunc(pattern, handler) - - return updatesChan, handler + return updatesChan } // AnswerInlineQuery sends a response to an inline query. diff --git a/bot_test.go b/bot_test.go index e61c87c..0d22046 100644 --- a/bot_test.go +++ b/bot_test.go @@ -5,9 +5,7 @@ import ( "io/ioutil" "log" "net/http" - "net/http/httptest" "os" - "strings" "testing" ) @@ -351,20 +349,6 @@ func TestGetUserProfilePhotos(t *testing.T) { } } -func TestListenForWebhook(t *testing.T) { - bot, _ := getBot(t) - - _, handler := bot.ListenForWebhook("/") - - req, _ := http.NewRequest("GET", "", strings.NewReader("{}")) - w := httptest.NewRecorder() - - handler.ServeHTTP(w, req) - if w.Code != http.StatusOK { - t.Errorf("Home page didn't return %v", http.StatusOK) - } -} - func TestSetWebhookWithCert(t *testing.T) { bot, _ := getBot(t) @@ -445,7 +429,7 @@ func ExampleNewWebhook() { log.Fatal(err) } - updates, _ := bot.ListenForWebhook("/" + bot.Token) + updates := bot.ListenForWebhook("/" + bot.Token) go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) for update := range updates {