-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (71 loc) · 1.63 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
// Create a network speed test cli
package main
// Import packages
import (
"fmt"
"io/ioutil"
"net/http"
"time"
)
// Define variables
var (
urls = []string{
"https://www.google.com",
"https://www.cox.com",
"https://www.facebook.com",
"https://www.youtube.com",
"https://www.amazon.com",
"https://www.reddit.com",
"https://www.wikipedia.org",
"https://www.instagram.com",
"https://www.twitter.com",
"https://www.linkedin.com",
"https://www.baidu.com",
"https://www.qq.com",
"https://www.taobao.com",
"https://www.live.com",
"https://www.tmall.com",
"https://www.yahoo.com",
"https://www.sohu.com",
"https://www.sina.com.cn",
"https://www.pinterest.com",
"https://www.microsoft.com",
"https://www.apple.com",
"https://www.ebay.com",
"https://www.paypal.com",
"https://www.microsoft.com/en-us/store/apps",
"https://www.microsoft.com/en-us/windows/microsoft-edge",
"https://www.groupon.com",
}
// Define a function to run the test
runTest = func(url string) (time.Duration, error) {
start := time.Now()
resp, err := http.Get(url)
if err != nil {
return 0, err
}
defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
return 0, err
}
return time.Since(start), nil
}
)
// Define a function to print the results
func printResults(url string, duration time.Duration) {
fmt.Printf("%s: %s\n", url, duration)
}
// Define a function to run the test
func main() {
// Run the test for each url
for _, url := range urls {
duration, err := runTest(url)
if err != nil {
fmt.Printf("Error: %s\n", err)
continue
}
printResults(url, duration)
}
}
// End of file