Skip to content

Instantly share code, notes, and snippets.

@ErezYalon
Last active August 12, 2020 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErezYalon/5c14ba5ecb22af0a143168243e386f32 to your computer and use it in GitHub Desktop.
Save ErezYalon/5c14ba5ecb22af0a143168243e386f32 to your computer and use it in GitHub Desktop.
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