$ # go run dlMulti.go urls...
$ go run dlMulti.go https://google.ca https://blog.golang.org https://twitter.com
Created
January 19, 2016 12:11
-
-
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
This file contains hidden or 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" | |
"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