github-vet / github-vet/rangeloop-pointer-findings
go-courses/youtubebot: bot/bot.go; 64 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [go-courses/youtubebot](https://www.github.com/go-courses/youtubebot) at [bot/bot.go](https://github.com/go-courses/youtubebot/blob/35e3625ba82199d1958b01bd2f731ddaada02cea/bot/bot.go#L95-L158)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable update used in defer or goroutine at line 111
[Click here to see the code in its original context.](https://github.com/go-courses/youtubebot/blob/35e3625ba82199d1958b01bd2f731ddaada02cea/bot/bot.go#L95-L158)
Click here to show the 64 line(s) of Go which triggered the analyzer.
```go
for update := range b.updates {
if update.Message == nil {
continue
}
text := update.Message.Text
if text == "" || text == "/start" {
continue
}
converted := make(chan bool, 1)
searched := make(chan bool, 1)
b.sendMsg(update, "Начал поиск")
fmt.Println(lastId)
go func() {
for {
tex := tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Ищу.")
b.tgAPI.Send(tex)
tex = tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Ищу..")
b.tgAPI.Send(tex)
tex = tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Ищу...")
b.tgAPI.Send(tex)
tex = tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Ищу....")
b.tgAPI.Send(tex)
if <-searched {
break
}
}
}()
youtubeID, err := b.search(text)
if err != nil {
log.Println("could not get video id from youtube", err)
}
url, title, err := GetDownloadURL(youtubeID)
if err != nil {
log.Println("could not get download url", err)
}
searched <- true
go func() {
for {
tex := tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Конвертирую.")
b.tgAPI.Send(tex)
tex = tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Конвертирую..")
b.tgAPI.Send(tex)
tex = tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Конвертирую...")
b.tgAPI.Send(tex)
tex = tgbotapi.NewEditMessageText(update.Message.Chat.ID, lastId, "Конвертирую....")
b.tgAPI.Send(tex)
if <-converted {
break
}
}
}()
err = Convert(title, url)
if err != nil {
log.Println("could not convert video file to mp3 ", err)
}
converted <- true
fileName := fmt.Sprintf("%s/%s.mp3", b.c.WorkingDirectory, title)
b.sendAudio(update, fileName)
os.Remove(fileName)
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 35e3625ba82199d1958b01bd2f731ddaada02cea
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.