Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Output improvement + go fmt

  • Loading branch information...
commit 8ad9b0e346eea9f2478c23e197cd401ba8824d39 1 parent 8943bba
Matthieu Tourne authored
Showing with 14 additions and 15 deletions.
  1. +14 −15 gurl.go
View
29 gurl.go
@@ -32,16 +32,17 @@ func connect(start, done chan bool, url string) {
defer r.Body.Close()
- body, err := ioutil.ReadAll(r.Body)
-
- if err != nil {
- log.Fatal(err)
- done <- true
- return
- }
-
// Print the body
if VERBOSE > 0 {
+
+ body, err := ioutil.ReadAll(r.Body)
+
+ if err != nil {
+ log.Fatal(err)
+ done <- true
+ return
+ }
+
fmt.Printf(string(body))
}
@@ -49,7 +50,6 @@ func connect(start, done chan bool, url string) {
}
}
-
// Goroutine to keep consuming <-done
func requests_done(done, end chan bool, n, c int) {
@@ -58,7 +58,7 @@ func requests_done(done, end chan bool, n, c int) {
for i := 0; i < n; i++ {
<-done
- if i % c == 0 && i != 0 {
+ if i%c == 0 && i != 0 {
now := time.Now().UnixNano()
interval := (now - last_now) / 1e6
fmt.Printf("%d reqs done. + %d msecs\n", i, interval)
@@ -66,15 +66,15 @@ func requests_done(done, end chan bool, n, c int) {
}
}
- fmt.Printf("%d reqs done.\n", n)
+ interval := (time.Now().UnixNano() - last_now) / 1e6
+ fmt.Printf("%d reqs done. + %d msecs\n", n, interval)
- total_time := (time.Now().UnixNano() - start_time) / 1e6
- fmt.Printf("\ntotal time: %d msecs\n", total_time)
+ total_time := time.Now().UnixNano() - start_time
+ fmt.Printf("\ntotal time: %f secs\n", float64(total_time)/1e9)
end <- true
}
-
func main() {
url := flag.String("url", "", "url to connect to: 'https://www.google.com'")
@@ -97,7 +97,6 @@ func main() {
start := make(chan bool, *n)
done := make(chan bool, *n)
-
end := make(chan bool, *n)
// just one request
Please sign in to comment.
Something went wrong with that request. Please try again.