* lib/model: Remove bogus fields from connections API endpoint. Switch the returned data type for the /rest/system/connections element "total" to use only the Statistics struct. The other fields of the ConnectionInfo struct are not populated and misleading. * Lowercase JSON field names. * lib/model: Get rid of ConnectionInfo.MarshalJSON(). It was missing the StartedAt field from the embedded Statistics struct. Just lowercasing the JSON attribute names can be done just as easily with annotations. * lib/model: Remove bogus startedAt field from totals. Instead of using the Statistics type with one field empty, just switch to a free-form map with the three needed fields.
This commit is contained in:
+10
-26
@@ -706,26 +706,12 @@ func (m *model) UsageReportingStats(report *contract.Report, version int, previe
|
|||||||
|
|
||||||
type ConnectionInfo struct {
|
type ConnectionInfo struct {
|
||||||
protocol.Statistics
|
protocol.Statistics
|
||||||
Connected bool
|
Connected bool `json:"connected"`
|
||||||
Paused bool
|
Paused bool `json:"paused"`
|
||||||
Address string
|
Address string `json:"address"`
|
||||||
ClientVersion string
|
ClientVersion string `json:"clientVersion"`
|
||||||
Type string
|
Type string `json:"type"`
|
||||||
Crypto string
|
Crypto string `json:"crypto"`
|
||||||
}
|
|
||||||
|
|
||||||
func (info ConnectionInfo) MarshalJSON() ([]byte, error) {
|
|
||||||
return json.Marshal(map[string]interface{}{
|
|
||||||
"at": info.At,
|
|
||||||
"inBytesTotal": info.InBytesTotal,
|
|
||||||
"outBytesTotal": info.OutBytesTotal,
|
|
||||||
"connected": info.Connected,
|
|
||||||
"paused": info.Paused,
|
|
||||||
"address": info.Address,
|
|
||||||
"clientVersion": info.ClientVersion,
|
|
||||||
"type": info.Type,
|
|
||||||
"crypto": info.Crypto,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NumConnections returns the current number of active connected devices.
|
// NumConnections returns the current number of active connected devices.
|
||||||
@@ -769,12 +755,10 @@ func (m *model) ConnectionStats() map[string]interface{} {
|
|||||||
res["connections"] = conns
|
res["connections"] = conns
|
||||||
|
|
||||||
in, out := protocol.TotalInOut()
|
in, out := protocol.TotalInOut()
|
||||||
res["total"] = ConnectionInfo{
|
res["total"] = map[string]interface{}{
|
||||||
Statistics: protocol.Statistics{
|
"at": time.Now().Truncate(time.Second),
|
||||||
At: time.Now().Truncate(time.Second),
|
"inBytesTotal": in,
|
||||||
InBytesTotal: in,
|
"outBytesTotal": out,
|
||||||
OutBytesTotal: out,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -994,10 +994,10 @@ func (c *rawConnection) pingReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Statistics struct {
|
type Statistics struct {
|
||||||
At time.Time
|
At time.Time `json:"at"`
|
||||||
InBytesTotal int64
|
InBytesTotal int64 `json:"inBytesTotal"`
|
||||||
OutBytesTotal int64
|
OutBytesTotal int64 `json:"outBytesTotal"`
|
||||||
StartedAt time.Time
|
StartedAt time.Time `json:"startedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) Statistics() Statistics {
|
func (c *rawConnection) Statistics() Statistics {
|
||||||
|
|||||||
Reference in New Issue
Block a user