From a842f32533eb68d3f4a0e88558d2f3d6b2dad790 Mon Sep 17 00:00:00 2001 From: Dmitry V Date: Wed, 18 Jan 2017 13:31:12 +0300 Subject: [PATCH] Added ability to set custom buffer size for webhook --- bot.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bot.go b/bot.go index 60519cd..88996f0 100644 --- a/bot.go +++ b/bot.go @@ -482,9 +482,19 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (updatesChannel, error) { return ch, nil } -// ListenForWebhook registers a http handler for a webhook. +// ListenForWebhook registers a http handler for a webhook with custom buffer size. +// Beware: larger values will increase memory consumption. +func (bot *BotAPI) ListenForWebhookWithBufferSize(pattern string, bufferSize int) updatesChannel { + return listenForWebhookWithBufferSize(pattern, bufferSize) +} + +// ListenForWebhook registers a http handler for a webhook, with buffer size set to default value - 100. func (bot *BotAPI) ListenForWebhook(pattern string) updatesChannel { - ch := make(chan Update, 100) + return listenForWebhookWithBufferSize(pattern, 100) +} + +func listenForWebhookWithBufferSize(pattern string, bufferSize int) updatesChannel { + ch := make(chan Update, bufferSize) http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { bytes, _ := ioutil.ReadAll(r.Body)