1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-07-03 11:53:43 +02:00

eosapi/functions.go: minor fixes.

This commit is contained in:
Henrik Hautakoski 2020-03-06 11:26:16 +01:00
parent a2327555f9
commit 5dc55e9ac7

View file

@ -3,25 +3,25 @@ package eosapi;
import ( import (
"time" "time"
"io/ioutil"
"net/url" "net/url"
"io/ioutil"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/liamylian/jsontime/v2" "github.com/liamylian/jsontime/v2"
) )
var json = v2.ConfigWithCustomTimeFormat; var json = v2.ConfigWithCustomTimeFormat
func init() { func init() {
// EOS Api does not specify timezone in timestamps (they are always UTC tho). // EOS Api does not specify timezone in timestamps (they are always UTC tho).
v2.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC); v2.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC)
} }
func send(method string, api_url string) (*req.Resp, error) { func send(method string, api_url string) (*req.Resp, error) {
u, err := url.Parse(api_url) u, err := url.Parse(api_url)
if err != nil { if err != nil {
return nil, err; return nil, err
} }
// 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.
@ -39,30 +39,30 @@ func send(method string, api_url string) (*req.Resp, error) {
// --------------------------------------------------------- // ---------------------------------------------------------
func GetInfo(url string) (Info, error) { func GetInfo(url string) (Info, error) {
var info Info; var info Info
r, err := send("GET", url + "/v1/chain/get_info"); r, err := send("GET", url + "/v1/chain/get_info")
if err == nil { if err == nil {
resp := r.Response() resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body); body, _ := ioutil.ReadAll(resp.Body)
// Parse json // Parse json
err = json.Unmarshal(body, &info); err = json.Unmarshal(body, &info)
} }
return info, err; return info, err
} }
func GetHealth(url string) (Health, error) { func GetHealth(url string) (Health, error) {
var health Health; var health Health;
r, err := send("GET", url + "/v2/health"); r, err := send("GET", url + "/v2/health")
if err == nil { if err == nil {
resp := r.Response() resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body); body, _ := ioutil.ReadAll(resp.Body)
// Parse json // Parse json
err = json.Unmarshal(body, &health); err = json.Unmarshal(body, &health)
} }
return health, err; return health, err
} }