1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-17 04:50:02 +02:00

src/api/v1.go: Adding SetTime() and GetTime()

This commit is contained in:
Henrik Hautakoski 2022-08-17 11:39:28 +02:00
parent 513beee79a
commit f16dced21c
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

View file

@ -11,6 +11,7 @@ import (
type EosioV1 struct {
params eosapi.ReqParams
block_time float64
ts time.Time
}
func NewEosioV1(url string, host string, block_time float64) EosioV1 {
@ -38,6 +39,18 @@ func (e EosioV1) LogInfo() LogParams {
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) {
info, err := eosapi.GetInfo(e.params)
@ -56,7 +69,7 @@ func (e EosioV1) Call() (agentcheck.Response, string) {
}
// Validate head block.
now := time.Now().In(time.UTC)
now := e.GetTime()
diff := now.Sub(info.HeadBlockTime).Seconds()
if diff > e.block_time {