From 9fbf12ef0b8ef9782961c178bfd5f22152bae237 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Fri, 2 Aug 2019 19:12:28 +0800 Subject: [PATCH] add --- docs/precog/sql_dump/precog_shema.sql | 1 + toolbar/precog/database/orm/node.go | 42 ++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/docs/precog/sql_dump/precog_shema.sql b/docs/precog/sql_dump/precog_shema.sql index 82378914..ba2c4e85 100644 --- a/docs/precog/sql_dump/precog_shema.sql +++ b/docs/precog/sql_dump/precog_shema.sql @@ -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, diff --git a/toolbar/precog/database/orm/node.go b/toolbar/precog/database/orm/node.go index f80716bb..00813242 100644 --- a/toolbar/precog/database/orm/node.go +++ b/toolbar/precog/database/orm/node.go @@ -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, + }) } -- 2.11.0