-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.go
More file actions
49 lines (39 loc) · 882 Bytes
/
Copy pathresponse.go
File metadata and controls
49 lines (39 loc) · 882 Bytes
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
package essqlclient
import (
"encoding/json"
"fmt"
)
type version struct {
Version struct {
Number *string `json:"number"`
} `json:"version"`
}
type sqlColumn struct {
Name string `json:"name"`
Type string `json:"type"`
}
type precookedResponse struct {
Columns []sqlColumn `json:"columns"`
Rows [][]interface{}
}
type SqlResponse struct {
Columns []sqlColumn
Rows []map[string]interface{}
}
func parseJsonResponse(b []byte) (*SqlResponse, error) {
var sql SqlResponse
var raw precookedResponse
err := json.Unmarshal(b, &raw)
if err != nil {
return nil, fmt.Errorf("es: response parse: %s", err.Error())
}
sql.Columns = raw.Columns
for _, rawRow := range raw.Rows {
row := make(map[string]interface{}, len(sql.Columns))
for k, v := range rawRow {
row[sql.Columns[k].Name] = v
}
sql.Rows = append(sql.Rows, row)
}
return &sql, nil
}