-
Notifications
You must be signed in to change notification settings - Fork 10
/
result.go
41 lines (35 loc) · 1.05 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
package hazana
import (
"fmt"
"strings"
"time"
)
type result struct {
begin, end time.Time
elapsed time.Duration
doResult DoResult
}
// DoResult is the return value of a Do call on an Attack.
type DoResult struct {
// Label identifying the request that was send which is only used for reporting the metrics.
// Use the RequesLabelSeparator to have multiple labels.
RequestLabel string
// The error that happened when sending the request or receiving the response.
Error error
// The HTTP status code.
StatusCode int
// Number of bytes transferred when sending the request.
BytesIn int64
// Number of bytes transferred when receiving the response.
BytesOut int64
}
// RequesLabelSeparator is what it says
var RequesLabelSeparator = ","
// WithLabels return a copy with multiple Request labels set.
func (d DoResult) WithLabels(labels ...string) DoResult {
d.RequestLabel = strings.Join(labels, RequesLabelSeparator)
return d
}
func (d DoResult) String() string {
return fmt.Sprintf("%s,status=%d,error=%v", d.RequestLabel, d.StatusCode, d.Error)
}