-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.go
61 lines (53 loc) · 1.24 KB
/
result.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
package main
import (
"fmt"
"github.com/gocolly/colly"
)
type result struct {
resp []*colly.Response
e4xx int
e5xx int
eOther int
errs []warmerError
}
func (r *result) addResponse(o options, resp *colly.Response) {
r.resp = append(r.resp, resp)
if o.verbose {
fmt.Printf("%s\n", resp.Request.URL)
} else {
r.printTerminal(o)
}
}
func (r *result) addError(o options, err warmerError) {
r.errs = append(r.errs, err)
if 400 <= err.response.StatusCode && err.response.StatusCode < 500 {
r.e4xx++
if o.verbose {
fmt.Print("4")
}
} else if 500 <= err.response.StatusCode && err.response.StatusCode < 600 {
r.e5xx++
if o.verbose {
fmt.Print("5")
}
} else {
r.eOther++
if o.verbose {
fmt.Print("e")
}
}
if !o.verbose && o.isTerminal {
r.printTerminal(o)
}
}
func (r *result) print(o options) {
fmt.Printf("responses: %d, 4xx: %d, 5xx: %d, other: %d", len(r.resp), r.e4xx, r.e5xx, r.eOther)
}
func (r *result) printTerminal(o options) {
fmt.Printf("\rresponses: %d, 4xx: %d, 5xx: %d, other: %d", len(r.resp), r.e4xx, r.e5xx, r.eOther)
}
func (r *result) printErrors(o options) {
for _, err := range r.errs {
fmt.Printf("\n%d: %s, %s", err.response.StatusCode, err.response.Request.URL, err.Error())
}
}