about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-03-15 00:41:38 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-03-15 00:41:38 +0100
commit10d94786ec39dc639d005134526281293cb0c802 (patch)
tree337133a00272e56b882dc7b96d79b657ee6b4f17
parent30eef8f7202af3cd09cd371b356d31c97a0573b1 (diff)
downloadhtping-10d94786ec39dc639d005134526281293cb0c802.tar.gz
htping-10d94786ec39dc639d005134526281293cb0c802.tar.xz
htping-10d94786ec39dc639d005134526281293cb0c802.zip
simplify handling of failed requests
-rw-r--r--htping.go26
1 files 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: