mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-06-18 05:00:03 +02:00
Merge remote-tracking branch 'origin/bugfix/json-float64-parse-error' into devel
This commit is contained in:
commit
1abb1c8249
2 changed files with 20 additions and 2 deletions
|
|
@ -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"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
17
src/utils/json.go
Normal file
17
src/utils/json.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
package utils
|
||||
|
||||
// JsonGetInt64
|
||||
// performs float64 (json numbers are always float64)
|
||||
// type assertion and casts to int64.
|
||||
//
|
||||
// if the type assertion fails, the function defaults 0 (zero).
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func JsonGetInt64(input interface{}) (int64) {
|
||||
v, res := input.(float64)
|
||||
if res {
|
||||
return (int64) (v)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue