package main import sync time strings fmt const strToSearch golang con

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"sync"
"time"
"strings"
"fmt"
)
const strToSearch = `golang`
const countStreamMax = 5
func main() {
// Подготовка данных
urls := []string{
"qweqw",
"qwegolangqwe",
"adsda",
"cvdxbfghrgolang",
"vdrvdbvrt",
"ververwbve",
"vsvdfsvd",
"vsvdfvdvdfsvd",
"vsvdvdfvdffsvd",
"vsvdfsvdfvdvd",
}
for i := 0; i < 100; i++ {
urls = append(urls, urls[0:10]...)
}
// обработка данных
var wg sync.WaitGroup
var countStream int
var countFound int
for i := range urls {
wg.Add(1)
countStream++
go func(url string) {
defer wg.Done()
if strings.Contains(url, strToSearch) {
countFound++
}
countStream--
}(urls[i])
for {
if countStream >= countStreamMax {
time.Sleep(time.Nanosecond)
} else {
break
}
}
}
wg.Wait()
fmt.Printf("Кол-во вхождений: %d", countFound)
}