OSDN Git Service

fix
[bytom/vapor.git] / toolbar / precog / database / orm / node.go
index f0bb345..05a2cc4 100644 (file)
@@ -17,6 +17,7 @@ type Node struct {
        IP                       string
        Port                     uint16
        BestHeight               uint64
+       AvgLantencyMS            sql.NullInt64
        LatestDailyUptimeMinutes uint64
        Status                   uint8
        CreatedAt                time.Time `json:"alias"`
@@ -24,16 +25,22 @@ type Node struct {
 }
 
 func (n *Node) MarshalJSON() ([]byte, error) {
-       status, ok := common.StatusMap[n.Status]
+       status, ok := common.StatusLookupTable[n.Status]
        if !ok {
                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"`
@@ -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,
+               AvgLantencyMS:            avgLantencyMS,
                LatestDailyUptimeMinutes: n.LatestDailyUptimeMinutes,
-               Status: status,
-               // TODO:
+               Status:    status,
                UpdatedAt: time.Now(),
        })
 }