OSDN Git Service

add
authorHAOYUatHZ <haoyu@protonmail.com>
Fri, 2 Aug 2019 11:12:28 +0000 (19:12 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Fri, 2 Aug 2019 11:12:28 +0000 (19:12 +0800)
docs/precog/sql_dump/precog_shema.sql
toolbar/precog/database/orm/node.go

index 8237891..ba2c4e8 100644 (file)
@@ -38,6 +38,7 @@ CREATE TABLE `nodes` (
   `port` smallint unsigned NOT NULL DEFAULT '0',
   `best_height` int(11) DEFAULT '0',
   `lantency_ms` int(11) DEFAULT NULL,
+  `active_begin_time` timestamp,
   `status` tinyint(1) NOT NULL DEFAULT '0',
   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
index f80716b..0081324 100644 (file)
@@ -2,19 +2,39 @@ package orm
 
 import (
        "database/sql"
-
+       "encoding/json"
        "time"
 )
 
-// TODO: json
 type Node struct {
-       Alias      string        `json:"alias"`
-       PubKey     chainkd.XPub  `json:"pubkey"`
-       Host       string        `json:"host"`
-       Port       uint16        `json:"port"`
-       BestHeight uint64        `json:"best_height"`
-       LantencyMS sql.NullInt64 `json:"lantency_ms"`
-       Status     uint8         `json:"status"`
-       CreatedAt  time.Time
-       UpdatedAt  time.Time
+       Alias           string        `json:"alias"`
+       PubKey          chainkd.XPub  `json:"pubkey"`
+       Host            string        `json:"host"`
+       Port            uint16        `json:"port"`
+       BestHeight      uint64        `json:"best_height"`
+       LantencyMS      sql.NullInt64 `json:"lantency_ms"`
+       ActiveBeginTime time.Time     `json:"active_begin_time"`
+       Status          uint8         `json:"status"`
+       CreatedAt       time.Time
+       UpdatedAt       time.Time
+}
+
+// TODO:
+func (n *Node) MarshalJSON() ([]byte, error) {
+       return json.Marshal(&struct {
+               Alias      string        `json:"alias"`
+               PubKey     chainkd.XPub  `json:"pubkey"`
+               Host       string        `json:"host"`
+               Port       uint16        `json:"port"`
+               BestHeight uint64        `json:"best_height"`
+               LantencyMS sql.NullInt64 `json:"lantency_ms,omitempty"`
+               ActiveTime time.Duration `json:"active_time,omitempty"`
+               Status     string        `json:"status"`
+       }{
+               Alias:      n.Alias,
+               PubKey:     n.PubKey,
+               Host:       n.Host,
+               Port:       n.Port,
+               BestHeight: n.BestHeight,
+       })
 }