From e3182624fdf74a6724cfd17abb29527f9ff47897 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 1 Oct 2015 19:21:51 +0100 Subject: [PATCH] refactor: more obviously handle all target states in reporting --- router/status.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/router/status.go b/router/status.go index 095f42aa..c56ccd03 100644 --- a/router/status.go +++ b/router/status.go @@ -174,22 +174,29 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus } for address, target := range cm.targets { var state, info string - switch { - case target.state == TargetConnected: + switch target.state { + case TargetConnected: continue - case target.lastError == nil: - state = "connecting" - info = "" - case target.state == TargetAttempting: - state = "retrying" - info = target.lastError.Error() - default: - state = "failed" - retry := "never" + case TargetAttempting: + if target.lastError == nil { + state = "connecting" + info = "" + } else { + state = "retrying" + info = target.lastError.Error() + } + case TargetWaiting: + until := "never" if !target.tryAfter.IsZero() { - retry = target.tryAfter.String() + until = target.tryAfter.String() + } + if target.lastError == nil { // shouldn't happen + state = "waiting" + info = "until: " + until + } else { + state = "failed" + info = target.lastError.Error() + ", retry: " + until } - info = target.lastError.Error() + ", retry: " + retry } slice = append(slice, LocalConnectionStatus{address, true, state, info}) }