Setup WaitGroups for email unsubscribing

This commit is contained in:
2023-12-30 14:56:58 -06:00
parent f8ffafdb89
commit 41d1370588

20
main.go
View File

@@ -2,11 +2,11 @@ package main
import ( import (
"encoding/json" "encoding/json"
"math/rand"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/url" "net/url"
"os" "os"
"sync"
badger "github.com/dgraph-io/badger/v4" badger "github.com/dgraph-io/badger/v4"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@@ -169,15 +169,27 @@ func main() {
} }
}() }()
var wg sync.WaitGroup
// Process each email // Process each email
for email := range entries { for email := range entries {
log.Info().Str("email", email).Msg("Unsubscribing Email") log.Info().Str("email", email).Msg("Unsubscribing Email")
go Unsubscribe(email) wg.Add(1)
go func(email string) {
defer wg.Done()
Unsubscribe(email)
}(email)
// 1/2 chance to unsubscribe fake email // 1/2 chance to unsubscribe fake email
if rand.Intn(2) == 0 { if RandBool() {
log.Info().Str("email", email).Msg("Unsubscribing Fake Email") log.Info().Str("email", email).Msg("Unsubscribing Fake Email")
go Unsubscribe(email) wg.Add(1)
go func(email string) {
defer wg.Done()
go Unsubscribe(FakeEmail())
}(email)
} }
} }
wg.Wait()
} }