refactor: simplify target status reporting
This commit is contained in:
1 parent
e3182624fd
commit
41691957d2
1 file changed
+12
-16
+12
-16
@@ -173,32 +173,28 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
|
|||||||
slice = append(slice, LocalConnectionStatus{conn.RemoteTCPAddr(), conn.Outbound(), state, conn.Remote().String()})
|
slice = append(slice, LocalConnectionStatus{conn.RemoteTCPAddr(), conn.Outbound(), state, conn.Remote().String()})
|
||||||
}
|
}
|
||||||
for address, target := range cm.targets {
|
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 {
|
switch target.state {
|
||||||
case TargetConnected:
|
|
||||||
continue
|
|
||||||
case TargetAttempting:
|
|
||||||
if target.lastError == nil {
|
|
||||||
state = "connecting"
|
|
||||||
info = ""
|
|
||||||
} else {
|
|
||||||
state = "retrying"
|
|
||||||
info = target.lastError.Error()
|
|
||||||
}
|
|
||||||
case TargetWaiting:
|
case TargetWaiting:
|
||||||
until := "never"
|
until := "never"
|
||||||
if !target.tryAfter.IsZero() {
|
if !target.tryAfter.IsZero() {
|
||||||
until = target.tryAfter.String()
|
until = target.tryAfter.String()
|
||||||
}
|
}
|
||||||
if target.lastError == nil { // shouldn't happen
|
if target.lastError == nil { // shouldn't happen
|
||||||
state = "waiting"
|
add("waiting", "until: "+until)
|
||||||
info = "until: " + until
|
|
||||||
} else {
|
} else {
|
||||||
state = "failed"
|
add("failed", target.lastError.Error()+", retry: "+until)
|
||||||
info = 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
|
resultChan <- slice
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in new issue
Block a user