Skip to content

Instantly share code, notes, and snippets.

@odeke-em
Created January 19, 2016 12:11
Show Gist options
  • Save odeke-em/62a2fa34a58ccf553e7e to your computer and use it in GitHub Desktop.
Save odeke-em/62a2fa34a58ccf553e7e to your computer and use it in GitHub Desktop.
Fetch a URL and consume its body, useful for testing bandwidth limiting

Usage

$ # go run dlMulti.go urls...
$ go run dlMulti.go https://google.ca https://blog.golang.org https://twitter.com
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "expecting atleast one url\n")
os.Exit(1)
}
rest := os.Args[1:]
for _, url := range rest {
log.Printf("Fetching %q\n", url)
res, err := http.Get(url)
if err != nil {
log.Printf("err %v url %q\n", err, url)
continue
}
log.Printf("Successfully fetched %q\n", url)
n, _ := io.Copy(ioutil.Discard, res.Body)
log.Printf("read %d bytes from %q\n", n, url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment