From: boypt <1033514+boypt@users.noreply.github.com> Date: Thu, 23 May 2019 05:58:17 +0000 (+0800) Subject: allow ConnStats being marsheled to json X-Git-Tag: v1.2.0~3 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=25d76e04495c333df1241c8588732c5be4799fe8;p=btrtrc.git allow ConnStats being marsheled to json --- diff --git a/conn_stats.go b/conn_stats.go index a691fb34..06ec23f2 100644 --- a/conn_stats.go +++ b/conn_stats.go @@ -5,6 +5,7 @@ import ( "io" "reflect" "sync/atomic" + "encoding/json" pp "github.com/anacrolix/torrent/peer_protocol" ) @@ -65,6 +66,10 @@ func (me *Count) String() string { return fmt.Sprintf("%v", me.Int64()) } +func (me *Count) MarshalJSON() ([]byte, error) { + return json.Marshal(me.n) +} + func (cs *ConnStats) wroteMsg(msg *pp.Message) { // TODO: Track messages and not just chunks. switch msg.Type {