1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-08-26 20:48:13 +02:00

combine host, port parameters into one string and add scheme.

This commit is contained in:
Henrik Hautakoski 2020-03-06 11:23:28 +01:00
parent 07c73c2b4e
commit 9717354e22
2 changed files with 26 additions and 28 deletions

View file

@ -2,9 +2,9 @@
package eosapi;
import (
"fmt"
"time"
"io/ioutil"
"net/url"
"github.com/imroc/req"
"github.com/liamylian/jsontime/v2"
)
@ -17,26 +17,31 @@ func init() {
v2.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC);
}
func send(method string, host string, port int, uri string) (*req.Resp, error) {
func send(method string, api_url string) (*req.Resp, error) {
u, err := url.Parse(api_url)
if err != nil {
return nil, err;
}
// 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,
"Host": u.Host,
}
r := req.New()
return r.Do(method, fmt.Sprintf("http://%s:%d%s", host, port, uri), headers);
return r.Do(method, api_url, headers)
}
// GetInfo - Fetches get_info from API
// ---------------------------------------------------------
func GetInfo(host string, port int) (Info, error) {
func GetInfo(url string) (Info, error) {
var info Info;
r, err := send("GET", host, port, "/v1/chain/get_info");
r, err := send("GET", url + "/v1/chain/get_info");
if err == nil {
resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body);
@ -47,11 +52,11 @@ func GetInfo(host string, port int) (Info, error) {
return info, err;
}
func GetHealth(host string, port int) (Health, error) {
func GetHealth(url string) (Health, error) {
var health Health;
r, err := send("GET", host, port, "/v2/health");
r, err := send("GET", url + "/v2/health");
if err == nil {
resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body);