-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
188 lines (168 loc) · 4.11 KB
/
main.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
import (
"encoding/json"
"fmt"
"go-tests/fss"
"io/ioutil"
"log"
"net/http"
"os"
"runtime"
"sync"
"time"
)
func main() {
// start
UrlPingerAsync2()
}
func GitLanguages() {
repos := fss.ReadJsonGT()
jsonLangs := ""
//var commonData map[string]int
javaLines := 0
goLines := 0
pythonLines := 0
cLines := 0
htmlLines := 0
jsLines := 0
groovyLines := 0
kotlinLines := 0
log.Println("[] \033[34m Starting ...\033[32m")
for _, repo := range repos {
url := fmt.Sprintf("https://api.github.com/repos/AndriiMaliuta/%s/languages", repo.Name)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Printf("Error creating request for url: %v", err)
}
req.Header.Add("Authorization", "Bearer "+os.Getenv("GIT_TOKEN"))
resp, err2 := client().Do(req)
if err2 != nil {
return
}
langsByte, err3 := ioutil.ReadAll(resp.Body)
if err3 != nil {
return
}
var data map[string]int
err4 := json.Unmarshal(langsByte, &data)
if err4 != nil {
log.Panicln(err4)
}
for a := 0; a < len(data); a++ {
if _, found := data["Go"]; found {
goLines += data["Go"]
} else if _, found := data["Java"]; found {
javaLines += data["Java"]
} else if _, found := data["HTML"]; found {
htmlLines += data["HTML"]
} else if _, found := data["Python"]; found {
pythonLines += data["Python"]
} else if _, found := data["C"]; found {
cLines += data["C"]
} else if _, found := data["JavaScript"]; found {
jsLines += data["JavaScript"]
} else if _, found := data["Groovy"]; found {
groovyLines += data["Groovy"]
} else if _, found := data["Kotlin"]; found {
kotlinLines += data["Kotlin"]
} else if _, found := data["HTML"]; found {
htmlLines += data["HTML"]
}
log.Println(data)
}
jsonLangs += string(langsByte) + ","
//log.Println(data)
/*
{
"Go": 3842,
"Makefile": 183
}
*/
//var mapData map[string]int
//mapData, ok := data.(map[string]int)
//if !ok {
// log.Println("error when mapping data to map")
//}
}
log.Printf("GO: %d", goLines)
log.Printf("Java: %d", javaLines)
log.Printf("C: %d", cLines)
log.Printf("Pythond: %d", pythonLines)
log.Printf("Groovy: %d", groovyLines)
log.Printf("JS: %d", jsLines)
log.Printf("Kotlin: %d", kotlinLines)
log.Printf("HTML: %d", htmlLines)
}
func UrlPingerAsync2() {
urls := []string{
"https://us-central1-andmal-bot.cloudfunctions.net/gcp-java-perf-test", // java
"https://us-central1-silver-adapter-307718.cloudfunctions.net/go-test-parser", // Go
"https://us-west2-silver-adapter-307718.cloudfunctions.net/node-perf-db", // node
"https://us-central1-andmal-bot.cloudfunctions.net/python-perf-test", // python
"https://us-central1-andmal-bot.cloudfunctions.net/dotnet2", // dotnet
}
//OneUrlReq(urls[0], 20)
//OneUrlReq(urls[1], 20)
//OneUrlReq(urls[2], 100)
//OneUrlReq(urls[3], 100)
//OneUrlReq(urls[4], 20)
var wg sync.WaitGroup
for _, url := range urls {
wg.Add(1)
go func(url string) {
OneUrlReq(url, 30)
wg.Done()
}(url)
}
wg.Wait() // block
//time.Sleep(20000)
//fmt.Println("Wait group init")
//var wg sync.WaitGroup
//wg.Add(1)
//go MyFunc(&wg)
//wg.Wait()
//fmt.Println("Finished Main")
}
func OneUrlReq(url string, times int) {
//url := urls[0]
for i := 0; i < times; i++ {
response, err := http.Get(url)
if err != nil {
return
}
status := response.StatusCode
fmt.Printf(" -- Req %d for %s DONE. Status: %d \n", i, url, status)
}
}
func AllLinks(urls []string) {
for _, url := range urls {
fmt.Printf(" -- link is %s \n", url)
for i := 0; i < 30; i++ {
http.Get(url)
fmt.Printf(" -- Req %d for %s is DONE \n", i, url)
}
}
}
func WaitEx2() {
var wg sync.WaitGroup
runtime.GOMAXPROCS(50)
for i := 0; i < 20; i++ {
wg.Add(1)
//for i := 0; i < 5; i++ {
go func() {
response, err := http.Get("https://example.com")
if err != nil {
log.Println(err)
}
fmt.Println(response.Body)
defer wg.Done()
//time.Sleep(200)
}()
//}
}
//wg.Wait()
}
func client() *http.Client {
client := http.Client{Timeout: 8 * time.Second}
return &client
}