github-vet / github-vet/rangeloop-pointer-findings
ShoshinNikita/habrahabr-bot-go: internal/bot/mailout.go; 45 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [ShoshinNikita/habrahabr-bot-go](https://www.github.com/ShoshinNikita/habrahabr-bot-go) at [internal/bot/mailout.go](https://github.com/ShoshinNikita/habrahabr-bot-go/blob/351a7ce5195e7ff00faabf28919ee505f02ede72/internal/bot/mailout.go#L209-L253)
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 newArticle used in defer or goroutine at line 232
[Click here to see the code in its original context.](https://github.com/ShoshinNikita/habrahabr-bot-go/blob/351a7ce5195e7ff00faabf28919ee505f02ede72/internal/bot/mailout.go#L209-L253)
Click here to show the 45 line(s) of Go which triggered the analyzer.
```go
for newArticle := range bot.articles {
allUsers, err = userdb.GetAllUsers()
if err != nil {
logging.LogMinorError("mailout", "ошибка при попытке получить список всех пользователей", err)
return
}
// Создание списка пользователей, которым нужно отправлять статьи
users := func() (users []userdb.User) {
for _, user := range allUsers {
if user.Mailout {
users = append(users, user)
}
}
return users
}()
var wg sync.WaitGroup
for _, user := range users {
wg.Add(1)
go func(user userdb.User) {
defer wg.Done()
if shouldSend(user, newArticle) {
message := tgbotapi.NewMessage(user.ID, newArticle.message)
message.ParseMode = "HTML"
bot.messages <- message
}
}(user)
}
wg.Wait()
// Обновление ссылок в файле
allArticles := struct {
HabrArticles []string `json:"habr"`
}{
oldArticles.queue,
}
raw, _ := json.Marshal(allArticles)
err = ioutil.WriteFile("data/lastArticles.json", raw, 0644)
if err != nil {
logging.LogMinorError("Mailout", "попытка записать файл lastArticles.json", err)
}
}
```
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: 351a7ce5195e7ff00faabf28919ee505f02ede72
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.