mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
src/api/v1.go: use utils.Time
This commit is contained in:
parent
d3d0fb11d7
commit
e5ddffbc5a
1 changed files with 3 additions and 16 deletions
|
|
@ -3,15 +3,15 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"github.com/eosswedenorg/eosio-api-healthcheck/src/utils"
|
||||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||||
"github.com/eosswedenorg-go/eosapi"
|
"github.com/eosswedenorg-go/eosapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EosioV1 struct {
|
type EosioV1 struct {
|
||||||
|
utils.Time
|
||||||
params eosapi.ReqParams
|
params eosapi.ReqParams
|
||||||
block_time float64
|
block_time float64
|
||||||
ts time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEosioV1(url string, host string, block_time float64) EosioV1 {
|
func NewEosioV1(url string, host string, block_time float64) EosioV1 {
|
||||||
|
|
@ -39,18 +39,6 @@ func (e EosioV1) LogInfo() LogParams {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EosioV1) SetTime(t time.Time) {
|
|
||||||
e.ts = t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e EosioV1) GetTime() time.Time {
|
|
||||||
|
|
||||||
if e.ts.IsZero() {
|
|
||||||
return time.Now().In(time.UTC)
|
|
||||||
}
|
|
||||||
return e.ts
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e EosioV1) Call() (agentcheck.Response, string) {
|
func (e EosioV1) Call() (agentcheck.Response, string) {
|
||||||
|
|
||||||
info, err := eosapi.GetInfo(e.params)
|
info, err := eosapi.GetInfo(e.params)
|
||||||
|
|
@ -69,8 +57,7 @@ func (e EosioV1) Call() (agentcheck.Response, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate head block.
|
// Validate head block.
|
||||||
now := e.GetTime()
|
diff := e.GetTime().Sub(info.HeadBlockTime).Seconds()
|
||||||
diff := now.Sub(info.HeadBlockTime).Seconds()
|
|
||||||
|
|
||||||
if diff > e.block_time {
|
if diff > e.block_time {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue