Stop returning useless http.Handler from ListenForWebhook.
Syfaro syfaro@foxpaw.in
Sun, 03 Jan 2016 23:05:36 -0600
3 files changed,
5 insertions(+),
23 deletions(-)
M
bot.go
→
bot.go
@@ -452,10 +452,10 @@ return updatesChan, nil
} // 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 @@
updatesChan <- update }) - http.HandleFunc(pattern, handler) - - return updatesChan, handler + return updatesChan } // AnswerInlineQuery sends a response to an inline query.
M
bot_test.go
→
bot_test.go
@@ -5,9 +5,7 @@ "github.com/go-telegram-bot-api/telegram-bot-api"
"io/ioutil" "log" "net/http" - "net/http/httptest" "os" - "strings" "testing" )@@ -351,20 +349,6 @@ t.Fail()
} } -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 @@ if err != nil {
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 {