From 10d94786ec39dc639d005134526281293cb0c802 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sun, 15 Mar 2020 00:41:38 +0100 Subject: simplify handling of failed requests --- htping.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/htping.go b/htping.go index f933814..ca2ee34 100644 --- a/htping.go +++ b/htping.go @@ -120,7 +120,6 @@ func ping(url string, seq int, results chan result) { req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Printf("error=%v\n", err) - results <- result{0, -1} return } @@ -143,7 +142,6 @@ func ping(url string, seq int, results chan result) { res, err := client.Do(req) if err != nil { fmt.Printf("error=%v\n", err) - results <- result{0, -1} return } @@ -180,19 +178,17 @@ func stats(results chan result, done chan bool) { for { select { case r := <-results: - if r.code > 0 { - if r.dur < min { - min = r.dur - } - if r.dur > max { - max = r.dur - } - sum += r.dur - sum2 += r.dur * r.dur - nrecv++ - if r.code <= 400 { - nsucc++ - } + if r.dur < min { + min = r.dur + } + if r.dur > max { + max = r.dur + } + sum += r.dur + sum2 += r.dur * r.dur + nrecv++ + if r.code <= 400 { + nsucc++ } case <-done: -- cgit 1.4.1