Last active
August 12, 2020 16:09
-
-
Save ErezYalon/5c14ba5ecb22af0a143168243e386f32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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