-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworkresult.go
97 lines (75 loc) · 1.87 KB
/
workresult.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"net/url"
"strings"
"time"
)
type WorkResult struct {
err error
parentURL url.URL
url url.URL
numberOfWorkers int
workerID int
responseSize int
body []byte
header map[string][]string
statusCode int
startTime time.Time
endTime time.Time
contentType string
}
func (workResult WorkResult) String() string {
headers := []string{}
for name, value := range workResult.header {
headers = append(headers, fmt.Sprintf("'%s:%s'", name, value))
}
return fmt.Sprintf("#%03d: %03d %9s %15s %20s %20s %s",
workResult.workerID,
workResult.statusCode,
fmt.Sprintf("%d", workResult.responseSize),
fmt.Sprintf("%fms", workResult.ResponseTime().Seconds()*1000),
workResult.url.String(),
workResult.parentURL.String(),
strings.Join(headers, "|"),
)
}
func (workResult WorkResult) Error() error {
return workResult.err
}
func (workResult WorkResult) ParentURL() url.URL {
return workResult.parentURL
}
func (workResult WorkResult) URL() url.URL {
return workResult.url
}
func (workResult WorkResult) Size() int {
return workResult.responseSize
}
func (workResult WorkResult) StatusCode() int {
return workResult.statusCode
}
func (workResult WorkResult) StartTime() time.Time {
return workResult.startTime
}
func (workResult WorkResult) EndTime() time.Time {
return workResult.endTime
}
func (workResult WorkResult) ResponseTime() time.Duration {
return workResult.endTime.Sub(workResult.startTime)
}
func (workResult WorkResult) ContentType() string {
return workResult.contentType
}
func (workResult WorkResult) WorkerID() int {
return workResult.workerID
}
func (workResult WorkResult) NumberOfWorkers() int {
return workResult.numberOfWorkers
}
func (workResult WorkResult) Body() []byte {
return workResult.body
}
func (workResult WorkResult) Header() map[string][]string {
return workResult.header
}