@@ -23,14 +23,16 @@ func GetURLHandlerInstance() LinkHandlerInterface {
23
23
24
24
// Handle - using scrap lib, check the link status
25
25
func (handler * urlHandler ) Handle (linkPath string ) int {
26
- respStatus , err := handler .scrap (linkPath , true )
26
+ respStatus , err := handler .scrap (linkPath )
27
27
for i := 0 ; i < 2 && err != nil ; i ++ {
28
28
errLower := strings .ToLower (err .Error ())
29
- respStatus , err = handler .scrap (linkPath , false )
30
- if err == nil {
31
- return respStatus
29
+ if strings .Contains (errLower , "eof" ) || strings .Contains (errLower , "timeout" ) {
30
+ respStatus , err = handler .scrap (linkPath )
31
+ if err == nil {
32
+ return respStatus
33
+ }
34
+ errLower = strings .ToLower (err .Error ())
32
35
}
33
- errLower = strings .ToLower (err .Error ())
34
36
if strings .Contains (errLower , "not found" ) {
35
37
return 404
36
38
}
@@ -48,13 +50,8 @@ func (handler *urlHandler) Handle(linkPath string) int {
48
50
return respStatus
49
51
}
50
52
51
- func (handler * urlHandler ) respStatusOK (restStatus int ) bool {
52
- return restStatus >= 200 && restStatus < 300 || restStatus >= 400 && restStatus < 500
53
- }
54
-
55
- func (handler * urlHandler ) scrap (linkPath string , checkHead bool ) (int , error ) {
53
+ func (handler * urlHandler ) scrap (linkPath string ) (int , error ) {
56
54
c := colly .NewCollector ()
57
- c .CheckHead = checkHead
58
55
respStatus := 0
59
56
c .OnResponse (func (resp * colly.Response ) {
60
57
respStatus = resp .StatusCode
0 commit comments