refactor: more obviously handle all target states in reporting

This commit is contained in:
Matthias Radestock committed 2015-10-01 20:05:12 +01:00
1 parent b8b3e6f9cd
commit e3182624fd
1 file changed
+20 -13
+20 -13
View File
@@ -174,22 +174,29 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
} }
for address, target := range cm.targets { for address, target := range cm.targets {
var state, info string var state, info string
switch { switch target.state {
case target.state == TargetConnected: case TargetConnected:
continue continue
case target.lastError == nil: case TargetAttempting:
state = "connecting" if target.lastError == nil {
info = "" state = "connecting"
case target.state == TargetAttempting: info = ""
state = "retrying" } else {
info = target.lastError.Error() state = "retrying"
default: info = target.lastError.Error()
state = "failed" }
retry := "never" case TargetWaiting:
until := "never"
if !target.tryAfter.IsZero() { 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}) slice = append(slice, LocalConnectionStatus{address, true, state, info})
} }