~xenrox/syncthing-status

d601fc185c6b9a2c09be5c09e4967a057f12131e — Thorben Günther 2 years ago 3922888
Use API to retrieve local device ID for filtering

/rest/system/connections returns the local device as well (as
unconnected). Filtering out by connection status could falsify the
output.
1 files changed, 13 insertions(+), 3 deletions(-)

M status.go
M status.go => status.go +13 -3
@@ 5,6 5,10 @@ import (
	"log"
)

type SystemStatus struct {
	MyID string `json:"myID"`
}

type LocalStatus struct {
	Completion float64 `json:"completion"`
}


@@ 35,15 39,21 @@ func (client *Client) localStatus() *LocalStatus {
func (client *Client) remoteStatus() *RemoteStatus {
	var totalStatus RemoteStatus
	var connections Connections
	var systemStatus SystemStatus

	err := client.get("/rest/system/status", &systemStatus)
	if err != nil {
		log.Fatal(err)
	}

	err := client.get("/rest/system/connections", &connections)
	err = client.get("/rest/system/connections", &connections)
	if err != nil {
		log.Fatal(err)
	}

	var connectedDevices []string
	for key, con := range connections.List {
		if con.Connected {
	for key := range connections.List {
		if key != systemStatus.MyID {
			connectedDevices = append(connectedDevices, key)
		}
	}