-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
result.go
146 lines (121 loc) · 3.57 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package http
import (
"encoding/json"
"fmt"
)
// HTTP result.
type Result struct {
data struct {
Af int `json:"af"`
Bsize int `json:"bsize"`
Dnserr string `json:"dnserr"`
DstAddr string `json:"dst_addr"`
Err string `json:"err"`
Header []string `json:"header"`
Hsize int `json:"hsize"`
Method string `json:"method"`
Readtiming json.RawMessage `json:"readtiming"`
Res int `json:"res"`
Rt float64 `json:"rt"`
SrcAddr string `json:"src_addr"`
Subid int `json:"subid"`
Submax int `json:"submax"`
Time int `json:"time"`
Ttc float64 `json:"ttc"`
Ttfb float64 `json:"ttfb"`
Ttr float64 `json:"ttr"`
Ver string `json:"ver"`
}
readtimings []*Readtiming
}
func (r *Result) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &r.data); err != nil {
return fmt.Errorf("%s for %s", err.Error(), string(b))
}
if r.data.Readtiming != nil {
if err := json.Unmarshal(r.data.Readtiming, &r.readtimings); err != nil {
return fmt.Errorf("Unable to process Readtiming: %s", err.Error())
}
}
return nil
}
// Address family, 4 or 6.
func (r *Result) Af() int {
return r.data.Af
}
// Size of body in octets.
func (r *Result) Bsize() int {
return r.data.Bsize
}
// DNS resolution failed (optional).
func (r *Result) Dnserr() string {
return r.data.Dnserr
}
// Target address.
func (r *Result) DstAddr() string {
return r.data.DstAddr
}
// Other failure (optional).
func (r *Result) Err() string {
return r.data.Err
}
// The last string can be empty to indicate the end of enders or end
// with "[...]" to indicate truncation (optional).
func (r *Result) Header() []string {
return r.data.Header
}
// Header size in octets.
func (r *Result) Hsize() int {
return r.data.Hsize
}
// "GET", "HEAD", or "POST".
func (r *Result) Method() string {
return r.data.Method
}
// Timing results for reply data (optional).
func (r *Result) Readtimings() []*Readtiming {
return r.readtimings
}
// HTTP result code.
func (r *Result) Res() int {
return r.data.Res
}
// Time to execute request excluding DNS.
func (r *Result) Rt() float64 {
return r.data.Rt
}
// Source address used by probe.
func (r *Result) SrcAddr() string {
return r.data.SrcAddr
}
// Sequence number of this result within a group of results, when
// the 'all' option is used without the 'combine' option (optional).
func (r *Result) Subid() int {
return r.data.Subid
}
// Total number of results within a group (optional).
func (r *Result) Submax() int {
return r.data.Submax
}
// Unix timestamp, when the 'all' option is used with the 'combine'
// option (optional).
func (r *Result) Time() int {
return r.data.Time
}
// Time to connect to the target (in milli seconds) (optional).
func (r *Result) Ttc() float64 {
return r.data.Ttc
}
// Time to first response byte received by measurent code after starting
// to connect (in milli seconds) (optional).
func (r *Result) Ttfb() float64 {
return r.data.Ttfb
}
// Time to resolve the DNS name (in milli seconds) (optional).
func (r *Result) Ttr() float64 {
return r.data.Ttr
}
// Major, minor version of http server.
func (r *Result) Ver() string {
return r.data.Ver
}