mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-04 12:03:43 +02:00
Replace local eosapi with github.com/eosswedenorg-go/eosapi
This commit is contained in:
parent
1d8b47762e
commit
44a01344c7
6 changed files with 4 additions and 123 deletions
4
go.mod
4
go.mod
|
|
@ -3,6 +3,7 @@ module github.com/eosswedenorg/eosio-api-healthcheck
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/eosswedenorg-go/eosapi v0.1.0
|
||||||
github.com/eosswedenorg-go/haproxy v0.0.0-20220101140534-fccfdd93a8cd
|
github.com/eosswedenorg-go/haproxy v0.0.0-20220101140534-fccfdd93a8cd
|
||||||
github.com/eosswedenorg-go/pid v1.0.0
|
github.com/eosswedenorg-go/pid v1.0.0
|
||||||
github.com/eosswedenorg-go/tcp_server v0.1.0
|
github.com/eosswedenorg-go/tcp_server v0.1.0
|
||||||
|
|
@ -10,10 +11,7 @@ require (
|
||||||
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
|
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
|
||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
github.com/pborman/getopt/v2 v2.1.0
|
github.com/pborman/getopt/v2 v2.1.0
|
||||||
internal/eosapi v1.0.0
|
|
||||||
internal/utils v1.0.0
|
internal/utils v1.0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
replace internal/eosapi => ./src/eosapi
|
|
||||||
|
|
||||||
replace internal/utils => ./src/utils
|
replace internal/utils => ./src/utils
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -1,6 +1,8 @@
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/eosswedenorg-go/eosapi v0.1.0 h1:SnVMx1QGPBZoQknjnAiGzjL6hVfrXPLrOdxoUstYUrk=
|
||||||
|
github.com/eosswedenorg-go/eosapi v0.1.0/go.mod h1:7VrkU30cSqRtGDE6bXygWqMcEhCyWOaC9yVA34QIQzM=
|
||||||
github.com/eosswedenorg-go/haproxy v0.0.0-20220101140534-fccfdd93a8cd h1:e59v3HnnG60uE50OtziOxyiSNDADr1lDbzn33btn3yE=
|
github.com/eosswedenorg-go/haproxy v0.0.0-20220101140534-fccfdd93a8cd h1:e59v3HnnG60uE50OtziOxyiSNDADr1lDbzn33btn3yE=
|
||||||
github.com/eosswedenorg-go/haproxy v0.0.0-20220101140534-fccfdd93a8cd/go.mod h1:l5DTEb0dcTZyATo2cuaYQPqwBRuzDw0UgupNo8SAgXo=
|
github.com/eosswedenorg-go/haproxy v0.0.0-20220101140534-fccfdd93a8cd/go.mod h1:l5DTEb0dcTZyATo2cuaYQPqwBRuzDw0UgupNo8SAgXo=
|
||||||
github.com/eosswedenorg-go/pid v1.0.0 h1:k1ra19cgWBHnX5gWQq+eUhNHIjT7hdhsYGp+Ovfvd2U=
|
github.com/eosswedenorg-go/pid v1.0.0 h1:k1ra19cgWBHnX5gWQq+eUhNHIjT7hdhsYGp+Ovfvd2U=
|
||||||
|
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
|
|
||||||
package eosapi;
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"net/url"
|
|
||||||
"io/ioutil"
|
|
||||||
"github.com/imroc/req"
|
|
||||||
jsontime "github.com/liamylian/jsontime/v2/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ReqParams struct {
|
|
||||||
Url string
|
|
||||||
Host string
|
|
||||||
}
|
|
||||||
|
|
||||||
var json = jsontime.ConfigWithCustomTimeFormat
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
|
|
||||||
// EOS Api does not specify timezone in timestamps (they are always UTC tho).
|
|
||||||
jsontime.SetDefaultTimeFormat("2006-01-02T15:04:05", time.UTC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func send(p ReqParams, method string, path string) (*req.Resp, error) {
|
|
||||||
|
|
||||||
host := p.Host
|
|
||||||
if len(host) < 1 {
|
|
||||||
u, err := url.Parse(p.Url)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
host = strings.Split(u.Host, ":")[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,
|
|
||||||
}
|
|
||||||
|
|
||||||
r := req.New()
|
|
||||||
return r.Do(method, p.Url + path, headers)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInfo - Fetches get_info from API
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
func GetInfo(params ReqParams) (Info, error) {
|
|
||||||
|
|
||||||
var info Info
|
|
||||||
|
|
||||||
r, err := send(params, "GET", "/v1/chain/get_info")
|
|
||||||
if err == nil {
|
|
||||||
resp := r.Response()
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
|
||||||
|
|
||||||
// Set HTTPStatusCode
|
|
||||||
info.HTTPStatusCode = resp.StatusCode
|
|
||||||
|
|
||||||
// Parse json
|
|
||||||
err = json.Unmarshal(body, &info)
|
|
||||||
}
|
|
||||||
return info, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetHealth(params ReqParams) (Health, error) {
|
|
||||||
|
|
||||||
var health Health;
|
|
||||||
|
|
||||||
r, err := send(params, "GET", "/v2/health")
|
|
||||||
if err == nil {
|
|
||||||
resp := r.Response()
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
|
||||||
|
|
||||||
// Set HTTPStatusCode
|
|
||||||
health.HTTPStatusCode = resp.StatusCode
|
|
||||||
|
|
||||||
// Parse json
|
|
||||||
err = json.Unmarshal(body, &health)
|
|
||||||
}
|
|
||||||
return health, err
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
module internal/eosapi
|
|
||||||
|
|
||||||
go 1.14
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/imroc/req v0.3.2
|
|
||||||
github.com/liamylian/jsontime/v2 v2.0.0
|
|
||||||
)
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
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"`
|
|
||||||
HTTPStatusCode int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Service struct from /v2/health
|
|
||||||
type Service struct {
|
|
||||||
Name string `json:"service"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Data map[string]interface{} `json:"service_data"`
|
|
||||||
Time int64 `json:"time"` // unix timestamp.
|
|
||||||
}
|
|
||||||
|
|
||||||
// /v2/health format (not all fields).
|
|
||||||
type Health struct {
|
|
||||||
VersionHash string `json:"version_hash"`
|
|
||||||
Health []Service `json:"health"`
|
|
||||||
HTTPStatusCode int
|
|
||||||
}
|
|
||||||
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"strings"
|
"strings"
|
||||||
"strconv"
|
"strconv"
|
||||||
"internal/eosapi"
|
|
||||||
"internal/utils"
|
"internal/utils"
|
||||||
|
"github.com/eosswedenorg-go/eosapi"
|
||||||
"github.com/eosswedenorg-go/haproxy"
|
"github.com/eosswedenorg-go/haproxy"
|
||||||
"github.com/eosswedenorg-go/tcp_server"
|
"github.com/eosswedenorg-go/tcp_server"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue