7
7
"log"
8
8
"net/http"
9
9
"os"
10
+ "sync"
10
11
)
11
12
12
13
const (
@@ -28,50 +29,62 @@ func main() {
28
29
members := getMembers ()
29
30
30
31
fmt .Println ("getting keys" )
32
+
31
33
getKeys (members )
32
34
}
33
35
34
36
func getKeys (members []member ) {
35
- client := & http.Client {}
36
-
37
37
var membersWithNoKey []member
38
-
38
+ var wg sync.WaitGroup
39
+ client := & http.Client {}
39
40
for _ , member := range members {
40
- req , err := http .NewRequest (
41
- "GET" ,
42
- fmt .Sprintf ("%s/%s.keys" , githubURL , member .Login ),
43
- nil ,
44
- )
45
- if err != nil {
46
- log .Fatal (err )
47
- }
48
- req .Header .Add ("authorization" , fmt .Sprintf ("token %s" , githubPat ))
49
-
50
- res , err := client .Do (req )
51
- if err != nil {
52
- log .Fatal (err )
53
- }
54
-
55
- defer res .Body .Close ()
56
-
57
- key , err := ioutil .ReadAll (res .Body )
58
- if err != nil {
59
- log .Fatal (err )
60
- }
61
-
62
- if len (key ) != 0 {
63
- fmt .Println (fmt .Sprintf ("%s:\n %s" , member .Login , key ))
64
- fmt .Println ("-------------------------------------------------------------------------------------" )
65
- fmt .Println ()
66
- } else {
67
- membersWithNoKey = append (membersWithNoKey , member )
68
- }
41
+ wg .Add (1 )
42
+ member := member
43
+
44
+ go func () {
45
+ defer wg .Done ()
46
+
47
+ req , err := http .NewRequest (
48
+ "GET" ,
49
+ fmt .Sprintf ("%s/%s.keys" , githubURL , member .Login ),
50
+ nil ,
51
+ )
52
+ if err != nil {
53
+ log .Fatal (err )
54
+ }
55
+ req .Header .Add ("authorization" , fmt .Sprintf ("token %s" , githubPat ))
56
+
57
+ res , err := client .Do (req )
58
+ if err != nil {
59
+ log .Fatal (err )
60
+ }
61
+
62
+ defer res .Body .Close ()
63
+
64
+ key , err := ioutil .ReadAll (res .Body )
65
+ if err != nil {
66
+ log .Fatal (err )
67
+ }
68
+
69
+ if len (key ) != 0 {
70
+ fmt .Println (fmt .Sprintf ("%s:\n %s" , member .Login , key ))
71
+ } else {
72
+ membersWithNoKey = append (membersWithNoKey , member )
73
+ }
74
+ }()
69
75
}
76
+ wg .Wait ()
70
77
71
- fmt .Println (fmt .Sprintf ("members with no keys (%d):" , len (membersWithNoKey )))
78
+ fmt .Println (fmt .Sprintf ("users with no key (%d):" , len (membersWithNoKey )))
72
79
for _ , member := range membersWithNoKey {
73
- fmt .Println (fmt .Sprintf ("%s" , member .Login ))
80
+ wg .Add (1 )
81
+ member := member
82
+ go func () {
83
+ defer wg .Done ()
84
+ fmt .Println (member .Login )
85
+ }()
74
86
}
87
+ wg .Wait ()
75
88
}
76
89
77
90
func getMembers () []member {
0 commit comments