This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequests.go
More file actions
67 lines (59 loc) · 1.34 KB
/
requests.go
File metadata and controls
67 lines (59 loc) · 1.34 KB
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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
type regionsInfo struct {
Regions []*regionInfo `json:"regions"`
}
type dbInfo struct {
Name struct {
O string `json:"O"`
L string `json:"L"`
} `json:"db_name"`
State int `json:"state"`
}
type tableInfo struct {
ID int64 `json:"id"`
Name struct {
O string `json:"O"`
L string `json:"L"`
} `json:"name"`
Indices []struct {
ID int64 `json:"id"`
Name struct {
O string `json:"O"`
L string `json:"L"`
} `json:"idx_name"`
} `json:"index_info"`
}
func request(addr string, uri string, v interface{}) {
resp, err := http.Get(fmt.Sprintf("%s/%s", addr, uri))
perr(err)
r, err := ioutil.ReadAll(resp.Body)
perr(err)
err = resp.Body.Close()
perr(err)
err = json.Unmarshal(r, v)
perr(err)
}
func regionRequest(key []byte, limit uint64) regionsInfo {
uri := fmt.Sprintf("pd/api/v1/regions/key?key=%s&limit=%d", url.QueryEscape(string(key)), limit)
var info regionsInfo
request(*pdAddr, uri, &info)
return info
}
func dbRequest(limit uint64) []*dbInfo {
var dbInfos = make([]*dbInfo, limit)
request(*tidbAddr, "schema", &dbInfos)
return dbInfos
}
func tableRequest(limit uint64, s string) []*tableInfo {
var tableInfos = make([]*tableInfo, limit)
uri := fmt.Sprintf("schema/%s", s)
request(*tidbAddr, uri, &tableInfos)
return tableInfos
}