~xenrox/syncthing-status

16149344a9babb2b5db6b780b931489552645151 — Thorben Günther 2 years ago 5a7a2e5
Simplify code
1 files changed, 7 insertions(+), 11 deletions(-)

M status.go
M status.go => status.go +7 -11
@@ 51,16 51,12 @@ func (client *Client) remoteStatus() *RemoteStatus {
		log.Fatal(err)
	}

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

	var sum float64
	for _, device := range connectedDevices {
		path := fmt.Sprintf("/rest/db/completion?device=%s", device)
		path := fmt.Sprintf("/rest/db/completion?device=%s", key)
		var status RemoteStatus
		err = client.get(path, &status)
		if err != nil {


@@ 70,11 66,11 @@ func (client *Client) remoteStatus() *RemoteStatus {
		sum += status.Completion
	}

	// Don't divide by zero
	if len(connectedDevices) == 0 {
	// Don't divide by zero; list contains local device as well
	if len(connections.List) == 1 {
		totalStatus.Completion = 100
	} else {
		totalStatus.Completion = sum / float64(len(connectedDevices))
		totalStatus.Completion = sum / float64(len(connections.List)-1)
	}

	return &totalStatus