Created
December 10, 2013 16:47
-
-
Save rubyist/7893846 to your computer and use it in GitHub Desktop.
GET some
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" | |
"net/http" | |
"os" | |
"strconv" | |
"sync" | |
) | |
func main() { | |
if len(os.Args) != 3 { | |
fmt.Println("Usage: <url> <n>") | |
os.Exit(1) | |
} | |
var wg sync.WaitGroup | |
n, _ := strconv.Atoi(os.Args[2]) | |
for i := 0; i < n; i++ { | |
q := i | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
resp, err := http.Get(os.Args[1]) | |
if err != nil { | |
fmt.Println("Error request") | |
return | |
} | |
defer resp.Body.Close() | |
f, err := os.OpenFile("/dev/null", os.O_RDWR, 0666) | |
if err != nil { | |
fmt.Println("Error opening null") | |
return | |
} | |
io.Copy(f, resp.Body) | |
fmt.Println("Done", q) | |
}() | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment