-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.go
103 lines (83 loc) · 2.85 KB
/
query.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
package gocensys
//QueryJob represents an SQL query job.
type QueryJob struct {
Status string `json:"status"`
Configuration struct {
Query string `json:"query"`
} `json:"configuration"`
JobID string `json:"job_id"`
Error string `json:"error"`
}
// QueryJobResults represents results of a query after it has completed successfully.
type QueryJobResults struct {
Statistics struct {
Rows float64 `json:"rows"`
Pages float64 `json:"pages"`
DataProcessed float64 `json:"data_processed"`
} `json:"statistics"`
Configuration struct {
Query string `json:"query"`
Page int `json:"page"`
Schema struct {
Fields []struct {
Type string `json:"type"`
Name string `json:"name"`
Mode string `json:"mode"`
} `json:"fields"`
} `json:"schema"`
} `json:"configuration"`
Rows []interface{} `json:"rows"`
}
//QuerySeriesDetails represents details about a series, including the list of tables and schema for the series.
type QuerySeriesDetails struct {
Definition struct {
Fields []struct {
Type string `json:"type"`
Name string `json:"name"`
Mode string `json:"mode"`
Fields []struct {
Type string `json:"type"`
Name string `json:"name"`
Mode string `json:"mode"`
} `json:"fields,omitempty"`
} `json:"fields"`
} `json:"definition"`
Tables []string `json:"tables"`
}
//QuerySeries represents series that can queried through the SQL interface.
type QuerySeries struct {
Series []string `json:"series"`
}
//StartQueryJob lets you to start a new asynchronous query job.
func (c CensysAPI) StartQueryJob(query string) (QueryJob, error) {
queryMap := map[string]interface{}{
"query": query,
}
var job QueryJob
err := c.apiPost("/query", queryMap, &job)
return job, err
}
//GetQueryJobStatus allows you to determine whether a job has completed.
func (c CensysAPI) GetQueryJobStatus(jobID string) (QueryJob, error) {
var job QueryJob
err := c.apiGet("/query/"+jobID, nil, &job)
return job, err
}
//GetQueryJobResults allows you to retrieve results of a query after it has completed successfully.
func (c CensysAPI) GetQueryJobResults(jobID, page string) (QueryJobResults, error) {
var results QueryJobResults
err := c.apiGet("/query/"+jobID+"/"+page, nil, &results)
return results, err
}
//GetQuerySeries returns a list of series that can queried through the SQL interface.
func (c CensysAPI) GetQuerySeries() (QuerySeries, error) {
var querySeries QuerySeries
err := c.apiGet("/query_definitions", nil, &querySeries)
return querySeries, err
}
//GetQuerySeriesDetails returns details about a series, including the list of tables and schema for the series.
func (c CensysAPI) GetQuerySeriesDetails(series string) (QuerySeriesDetails, error) {
var querySeriesDetails QuerySeriesDetails
err := c.apiGet("/query_definitions/"+series, nil, &querySeriesDetails)
return querySeriesDetails, err
}