mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
eosapi/functions.go: Adding GetHealth()
This commit is contained in:
parent
e6115260ef
commit
23ef00496d
1 changed files with 25 additions and 10 deletions
|
|
@ -17,14 +17,7 @@ func init() {
|
||||||
v2.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC);
|
v2.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInfo - Fetches get_info from API
|
func send(method string, host string, port int, uri string) (*req.Resp, error) {
|
||||||
// ---------------------------------------------------------
|
|
||||||
func GetInfo(host string, port int) (Info, error) {
|
|
||||||
|
|
||||||
var info Info;
|
|
||||||
|
|
||||||
// Format url.
|
|
||||||
url := fmt.Sprintf("http://%s:%d/v1/chain/get_info", host, port);
|
|
||||||
|
|
||||||
// Go's net.http (that `req` uses) sends the port in the host header.
|
// Go's net.http (that `req` uses) sends the port in the host header.
|
||||||
// nodeos api does not like that, so we need to provide our
|
// nodeos api does not like that, so we need to provide our
|
||||||
|
|
@ -33,8 +26,17 @@ func GetInfo(host string, port int) (Info, error) {
|
||||||
"Host": host,
|
"Host": host,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send HTTP Get request.
|
r := req.New()
|
||||||
r, err := req.Get(url, headers)
|
return r.Do(method, fmt.Sprintf("http://%s:%d%s", host, port, uri), headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInfo - Fetches get_info from API
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
func GetInfo(host string, port int) (Info, error) {
|
||||||
|
|
||||||
|
var info Info;
|
||||||
|
|
||||||
|
r, err := send("GET", host, port, "/v1/chain/get_info");
|
||||||
resp := r.Response()
|
resp := r.Response()
|
||||||
body, _ := ioutil.ReadAll(resp.Body);
|
body, _ := ioutil.ReadAll(resp.Body);
|
||||||
|
|
||||||
|
|
@ -42,3 +44,16 @@ func GetInfo(host string, port int) (Info, error) {
|
||||||
err = json.Unmarshal(body, &info);
|
err = json.Unmarshal(body, &info);
|
||||||
return info, err;
|
return info, err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetHealth(host string, port int) (Health, error) {
|
||||||
|
|
||||||
|
var health Health;
|
||||||
|
|
||||||
|
r, err := send("GET", host, port, "/v2/health");
|
||||||
|
resp := r.Response()
|
||||||
|
body, _ := ioutil.ReadAll(resp.Body);
|
||||||
|
|
||||||
|
// Parse json
|
||||||
|
err = json.Unmarshal(body, &health);
|
||||||
|
return health, err;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue