@@ -11,12 +11,16 @@ import (
11
11
"github.com/sirupsen/logrus"
12
12
)
13
13
14
+ // HttpClient provides an http client with a timeout for users
14
15
func HttpClient (timeout time.Duration ) * http.Client {
15
16
return & http.Client {
16
17
Timeout : timeout * time .Second ,
17
18
}
18
19
}
19
20
21
+ // FetchSource performs a get request for the given url and returns the body content
22
+ // @params url: target url
23
+ // @params timeout: timeout for request
20
24
func FetchSource (url string , timeout time.Duration ) (error , string ) {
21
25
client := HttpClient (timeout )
22
26
resp , err := client .Get (url )
@@ -43,7 +47,10 @@ type urlChecker struct {
43
47
client * http.Client
44
48
}
45
49
50
+ // Do is method of struct urlChecker.
51
+ // It performs GET request for the url and saves the result to log file.
46
52
func (c * urlChecker ) Do () {
53
+ fmt .Println (c .url )
47
54
defer func () {
48
55
if err := recover (); err != nil {
49
56
logrus .WithFields (logrus.Fields {
@@ -61,6 +68,7 @@ func (c *urlChecker) Do() {
61
68
logrus .WithFields (logrus.Fields {
62
69
"url" : c .url ,
63
70
}).Infoln ("Passed!" )
71
+ strChan <- c .url
64
72
} else {
65
73
logrus .WithFields (logrus.Fields {
66
74
"url" : c .url ,
@@ -69,10 +77,18 @@ func (c *urlChecker) Do() {
69
77
}
70
78
}
71
79
80
+ // CheckRangeSycn checks all the urls in the range given by url
81
+ // @params url: a url containing a range, through which we could get a sequence of urls within this range.
82
+ // The range must be a number range.
72
83
func CheckRangeSycn (url string , timeout time.Duration ) {
73
-
84
+ // generate all the urls according to the url range
85
+ urls := ParseRange (url )
86
+ // make use of CheckAllSync to complete this check
87
+ CheckAllSync (urls , timeout )
74
88
}
75
89
90
+ // CheckAllSync checks all the urls simultaneously
91
+ // @params urls: all the url that need to check
76
92
func CheckAllSync (urls []string , timeout time.Duration ) {
77
93
runtime .GOMAXPROCS (runtime .NumCPU ())
78
94
client := HttpClient (timeout )
0 commit comments