Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"fmt"
"os"
"net/http"
"time"
"io/ioutil"
"strconv"
)
func MakeRequest(url string, ch chan<-string) {
start := time.Now().UnixNano()
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
ch <- fmt.Sprintf("%d %s", start, body)
}
func main() {
url := os.Args[1]
nrOfRequests, _ := strconv.Atoi(os.Args[2])
ch := make(chan string)
for i := 0; i < nrOfRequests; i++ {
go MakeRequest(url, ch)
}
for i := 0; i < nrOfRequests; i++ {
fmt.Println(<-ch)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.