-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery.go
More file actions
60 lines (54 loc) · 912 Bytes
/
query.go
File metadata and controls
60 lines (54 loc) · 912 Bytes
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
57
58
59
60
package main
import (
"fmt"
"log"
"sync"
)
func runQuery(queriers []Querier, query string) bool {
if err := safeURLSegment(query); err != nil {
log.Fatal("invalid query: ", err)
}
type Result struct {
Name string
Found bool
}
results := make(chan Result)
var wg sync.WaitGroup
for _, q := range queriers {
if shouldSkipRepository(q.Name()) {
continue
}
wg.Add(1)
go func(q Querier) {
defer wg.Done()
found := false
if !*flagDryRun {
var err error
found, err = q.Query(query)
if err != nil {
log.Println(err)
return
}
}
results <- Result{
Name: q.Name(),
Found: found,
}
}(q)
}
go func() {
wg.Wait()
close(results)
}()
foundAny := false
for result := range results {
if result.Found {
fmt.Printf("*")
foundAny = true
} else {
fmt.Print("-")
}
fmt.Printf(" %s\n", result.Name)
}
return foundAny
}