forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.go
48 lines (42 loc) · 819 Bytes
/
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
package kapacitor
import (
"encoding/json"
"io"
"io/ioutil"
"time"
"github.com/influxdata/influxdb/influxql"
)
// The result from an output.
type Result influxql.Result
// Unmarshal a Result object from JSON.
func ResultFromJSON(in io.Reader) (r Result) {
b, err := ioutil.ReadAll(in)
if err != nil {
r.Err = err
return
}
_ = json.Unmarshal(b, &r)
// Convert all times to time.Time
ConvertResultTimes(&r)
return
}
func ConvertResultTimes(r *Result) {
for _, series := range r.Series {
for i, v := range series.Values {
for j, c := range series.Columns {
if c == "time" {
tStr, ok := v[j].(string)
if !ok {
continue
}
t, err := time.Parse(time.RFC3339, tStr)
if err != nil {
continue
}
series.Values[i][j] = t
break
}
}
}
}
}