-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
52 lines (44 loc) · 1.04 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
package main
import (
"flag"
"log"
"net/http"
"time"
)
var counter = 0
var urlString = flag.String("url", "https://some-url.com", "a site url")
var streams = flag.Int("streams", 42, "a number of streams")
var timeout = flag.Int("timeout", 1, "timeout in minutes for working of program")
func main() {
flag.Parse()
log.Println("Url:", *urlString)
log.Println("Streams number:", *streams)
sum := 1
for sum < *streams {
go storm(*urlString)
log.Println("Goroutine was created with number:", sum)
sum += 1
}
time.Sleep(time.Duration(*timeout) * time.Minute)
}
func storm(url string) {
for {
log.Println("Start load test on the url:", url)
resp, err := http.Get(url)
if err != nil {
log.Println("Got error code from url:", resp.Status)
return
} else {
log.Println("Load test passed successfuly:", resp.Status)
}
defer func() {
err := resp.Body.Close()
if err != nil {
log.Println("Error while closing connection", err)
}
return
}()
counter += 1
log.Println("Number of successful test:", counter)
}
}