From 41691957d2d730ae7d883a66eba4066e0528df33 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 1 Oct 2015 19:30:42 +0100 Subject: [PATCH] refactor: simplify target status reporting --- router/status.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/router/status.go b/router/status.go index c56ccd03..bbb10d41 100644 --- a/router/status.go +++ b/router/status.go @@ -173,32 +173,28 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus slice = append(slice, LocalConnectionStatus{conn.RemoteTCPAddr(), conn.Outbound(), state, conn.Remote().String()}) } for address, target := range cm.targets { - var state, info string + add := func(state, info string) { + slice = append(slice, LocalConnectionStatus{address, true, state, info}) + } switch target.state { - case TargetConnected: - continue - case TargetAttempting: - if target.lastError == nil { - state = "connecting" - info = "" - } else { - state = "retrying" - info = target.lastError.Error() - } case TargetWaiting: until := "never" if !target.tryAfter.IsZero() { until = target.tryAfter.String() } if target.lastError == nil { // shouldn't happen - state = "waiting" - info = "until: " + until + add("waiting", "until: "+until) } else { - state = "failed" - info = target.lastError.Error() + ", retry: " + until + add("failed", target.lastError.Error()+", retry: "+until) } + case TargetAttempting: + if target.lastError == nil { + add("connecting", "") + } else { + add("retrying", target.lastError.Error()) + } + case TargetConnected: } - slice = append(slice, LocalConnectionStatus{address, true, state, info}) } resultChan <- slice return false