OSDN Git Service

fix
authorHAOYUatHZ <haoyu@protonmail.com>
Sat, 31 Aug 2019 10:53:36 +0000 (18:53 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sat, 31 Aug 2019 10:53:36 +0000 (18:53 +0800)
toolbar/precog/database/orm/node.go
toolbar/precog/database/orm/node_liveness.go

index 120e950..05a2cc4 100644 (file)
@@ -17,6 +17,7 @@ type Node struct {
        IP                       string
        Port                     uint16
        BestHeight               uint64
        IP                       string
        Port                     uint16
        BestHeight               uint64
+       AvgLantencyMS            sql.NullInt64
        LatestDailyUptimeMinutes uint64
        Status                   uint8
        CreatedAt                time.Time `json:"alias"`
        LatestDailyUptimeMinutes uint64
        Status                   uint8
        CreatedAt                time.Time `json:"alias"`
@@ -29,11 +30,17 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                return nil, errors.New("fail to look up status")
        }
 
                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"`
        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"`
                LatestDailyUptimeMinutes uint64    `json:"latest_daily_uptime_minutes"`
                Status                   string    `json:"status"`
                UpdatedAt                time.Time `json:"updated_at"`
@@ -42,9 +49,9 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                PublicKey:                n.PublicKey,
                Address:                  fmt.Sprintf("%s:%d", n.IP, n.Port),
                BestHeight:               n.BestHeight,
                PublicKey:                n.PublicKey,
                Address:                  fmt.Sprintf("%s:%d", n.IP, n.Port),
                BestHeight:               n.BestHeight,
+               AvgLantencyMS:            avgLantencyMS,
                LatestDailyUptimeMinutes: n.LatestDailyUptimeMinutes,
                LatestDailyUptimeMinutes: n.LatestDailyUptimeMinutes,
-               Status: status,
-               // TODO:
+               Status:    status,
                UpdatedAt: time.Now(),
        })
 }
                UpdatedAt: time.Now(),
        })
 }
index c708129..91ff4ce 100644 (file)
@@ -6,14 +6,13 @@ import (
 )
 
 type NodeLiveness struct {
 )
 
 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"`
 }
 
        Node *Node `gorm:"foreignkey:NodeID"`
 }