From ba6b79ae0ecc8efd749f9f111bc7e483afd8a8ab Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 24 Jun 2020 14:41:13 +0200 Subject: [PATCH] src/server.go: in check_api_v2() use utils.JsonGetInt64() to safely get a int64 value from json. If json contains "nil" value, the type assertion will fail. JsonGetInt64() will in that case return "0" --- src/server.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server.go b/src/server.go index 595efcc..c46c799 100644 --- a/src/server.go +++ b/src/server.go @@ -9,6 +9,7 @@ import ( "./pid" "./haproxy" "./eosapi" + "./utils" "github.com/firstrow/tcp_server" "github.com/pborman/getopt/v2" ) @@ -55,9 +56,9 @@ func check_api_v2(p eosapi.ReqParams, offset int64) (haproxy.HealthCheckStatus, for _, v := range health.Health { if v.Name == "Elasticsearch" { - es_block = (int64) (v.Data["last_indexed_block"].(float64)) + es_block = utils.JsonGetInt64(v.Data["last_indexed_block"]) } else if v.Name == "NodeosRPC" { - node_block = (int64) (v.Data["head_block_num"].(float64)) + node_block = utils.JsonGetInt64(v.Data["head_block_num"]) } }