(w interface{ Write(p []byte) (int, error) }, all, ranked []scanner.IPResult)
| 318 | } |
| 319 | |
| 320 | func writeIPTable(w interface{ Write(p []byte) (int, error) }, all, ranked []scanner.IPResult) error { |
| 321 | tw := tabwriter.NewWriter(w, 0, 2, 2, ' ', 0) |
| 322 | |
| 323 | reachable := 0 |
| 324 | for _, r := range all { |
| 325 | if r.Reachable { |
| 326 | reachable++ |
| 327 | } |
| 328 | } |
| 329 | fmt.Fprintf(w, "Reachable: %d / %d\n\n", reachable, len(all)) |
| 330 | if len(ranked) == 0 { |
| 331 | fmt.Fprintln(w, "No reachable IPs. Network issue?") |
| 332 | return nil |
| 333 | } |
| 334 | // Sort displayed-ranked by RTT already, but keep it explicit. |
| 335 | sort.Slice(ranked, func(i, j int) bool { return ranked[i].RTT < ranked[j].RTT }) |
| 336 | fmt.Fprintln(tw, "RANK\tIP\tRTT") |
| 337 | for i, r := range ranked { |
| 338 | fmt.Fprintf(tw, "%d\t%s\t%s\n", |
| 339 | i+1, r.IP, r.RTT.Round(time.Millisecond)) |
| 340 | } |
| 341 | return tw.Flush() |
| 342 | } |
| 343 | |
| 344 | func min(a, b int) int { |
| 345 | if a < b { |
no outgoing calls
no test coverage detected