-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpq.go
91 lines (76 loc) · 1.88 KB
/
pq.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
package lrq
import (
"context"
"encoding/json"
"time"
)
type PQRequestAttribs struct {
StartTime *time.Time
EndTime *time.Time
}
type pqRequest struct {
QueryType string `json:"queryType"`
StartTime *int64 `json:"startTime,omitempty"`
EndTime *int64 `json:"endTime,omitempty"`
PQ pqRequestOpts `json:"pq"`
}
type pqRequestOpts struct {
Query string `json:"query"`
ResultType string `json:"resultType"`
}
func (c *Client) DoPQPlotRequest(ctx context.Context, query string, attribs PQRequestAttribs) (*PlotResponseData, error) {
reqBody := pqRequest{
QueryType: "PQ",
StartTime: timeToInt64(attribs.StartTime),
EndTime: timeToInt64(attribs.EndTime),
PQ: pqRequestOpts{
Query: query,
ResultType: "PLOT",
},
}
reqBytes, err := json.Marshal(reqBody)
if err != nil {
return nil, err
}
respBytes, err := c.doRequest(ctx, reqBytes)
if err != nil {
return nil, err
}
var respBody PlotResponseData
if err := json.Unmarshal(respBytes, &respBody); err != nil {
return nil, err
}
return &respBody, nil
}
type PQResponseData struct {
Values [][]interface{} `json:"values"`
Columns []struct {
Name string `json:"name"`
Type string `json:"cellType"`
} `json:"columns"`
Warnings []string `json:"warnings"`
}
func (c *Client) DoPQTableRequest(ctx context.Context, query string, attribs PQRequestAttribs) (*PQResponseData, error) {
reqBody := pqRequest{
QueryType: "PQ",
StartTime: timeToInt64(attribs.StartTime),
EndTime: timeToInt64(attribs.EndTime),
PQ: pqRequestOpts{
Query: query,
ResultType: "TABLE",
},
}
reqBytes, err := json.Marshal(reqBody)
if err != nil {
return nil, err
}
respBytes, err := c.doRequest(ctx, reqBytes)
if err != nil {
return nil, err
}
var respBody PQResponseData
if err := json.Unmarshal(respBytes, &respBody); err != nil {
return nil, err
}
return &respBody, nil
}