Change visibility of UpdatesChannel, closes #76

bot-api-6.1
Syfaro 2017-01-26 11:43:28 -06:00
parent 99170e2de4
commit 3293f3ad84
3 changed files with 8 additions and 9 deletions

4
bot.go
View File

@ -456,7 +456,7 @@ func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) {
}
// GetUpdatesChan starts and returns a channel for getting updates.
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (updatesChannel, error) {
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
ch := make(chan Update, 100)
go func() {
@ -483,7 +483,7 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (updatesChannel, error) {
}
// ListenForWebhook registers a http handler for a webhook.
func (bot *BotAPI) ListenForWebhook(pattern string) updatesChannel {
func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
ch := make(chan Update, 100)
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {

View File

@ -485,10 +485,9 @@ func ExampleNewBotAPI() {
updates, err := bot.GetUpdatesChan(u)
//If you need to clear all the updates when bot just started:
//Wait to gather all the new updates (choose the time conveniently)
// Optional: wait for updates and clear them if you don't want to handle
// a large backlog of old messages
time.Sleep(time.Millisecond * 500)
//discard all the updates preventing the spam after your server has been down
updates.Clear()
for update := range updates {

View File

@ -37,11 +37,11 @@ type Update struct {
CallbackQuery *CallbackQuery `json:"callback_query"`
}
//updatesChannel is the channel for getting updates.
type updatesChannel <-chan Update
// UpdatesChannel is the channel for getting updates.
type UpdatesChannel <-chan Update
//Clear discards all the actual incoming updates
func (ch updatesChannel) Clear() {
// Clear discards all unprocessed incoming updates.
func (ch UpdatesChannel) Clear() {
for len(ch) != 0 {
<-ch
}