1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-08-23 20:18:14 +02:00

Initial commit

This commit is contained in:
Henrik Hautakoski 2020-02-03 13:24:34 +01:00
commit 33c8439604
9 changed files with 270 additions and 0 deletions

44
eosapi/functions.go Normal file
View file

@ -0,0 +1,44 @@
package eosapi;
import (
"fmt"
"time"
"io/ioutil"
"github.com/imroc/req"
"github.com/liamylian/jsontime/v2"
)
var json = v2.ConfigWithCustomTimeFormat;
func init() {
// EOS Api does not specify timezone in timestamps (they are always UTC tho).
v2.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC);
}
// GetInfo - Fetches get_info from API
// ---------------------------------------------------------
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.
// nodeos api does not like that, so we need to provide our
// own Host header with just the host.
headers := req.Header{
"Host": host,
}
// Send HTTP Get request.
r, err := req.Get(url, headers)
resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body);
// Parse json
err = json.Unmarshal(body, &info);
return info, err;
}

11
eosapi/types.go Normal file
View file

@ -0,0 +1,11 @@
package eosapi;
import "time";
// get_info format (not all fields).
type Info struct {
ServerVersion string `json:"server_version"`
HeadBlockNum int64 `json:"head_block_num"`
HeadBlockTime time.Time `json:"head_block_time"`
}