IP string
Port uint16
BestHeight uint64
+ AvgLantencyMS sql.NullInt64
LatestDailyUptimeMinutes uint64
Status uint8
CreatedAt time.Time `json:"alias"`
return nil, errors.New("fail to look up status")
}
+ avgLantencyMS := 0
+ if n.AvgLantencyMS.Valid {
+ avgLantencyMS = n.AvgLantencyMS.Int64
+ }
+
return json.Marshal(&struct {
Alias string `json:"alias"`
PublicKey string `json:"publickey"`
Address string `json:"address"`
BestHeight uint64 `json:"best_height"`
+ AvgLantencyMS int64 `json:"avg_lantency_ms"`
LatestDailyUptimeMinutes uint64 `json:"latest_daily_uptime_minutes"`
Status string `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
PublicKey: n.PublicKey,
Address: fmt.Sprintf("%s:%d", n.IP, n.Port),
BestHeight: n.BestHeight,
+ AvgLantencyMS: avgLantencyMS,
LatestDailyUptimeMinutes: n.LatestDailyUptimeMinutes,
- Status: status,
- // TODO:
+ Status: status,
UpdatedAt: time.Now(),
})
}
)
type NodeLiveness struct {
- ID uint64 `gorm:"primary_key"`
- NodeID uint16
- PingTimes uint64
- PongTimes uint64
- AvgLantencyMS sql.NullInt64
- BestHeight uint64
- CreatedAt time.Time
- UpdatedAt time.Time
+ ID uint64 `gorm:"primary_key"`
+ NodeID uint16
+ PingTimes uint64
+ PongTimes uint64
+ BestHeight uint64
+ CreatedAt time.Time
+ UpdatedAt time.Time
Node *Node `gorm:"foreignkey:NodeID"`
}