Last active
April 9, 2016 16:45
-
-
Save jkakar/3ff610ad1fb7a8695865f804ef369a15 to your computer and use it in GitHub Desktop.
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 ( | |
"bufio" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"strings" | |
"time" | |
) | |
func DoRequest(url string) { | |
client := &http.Client{} | |
request, _ := http.NewRequest("PUT", url, strings.NewReader("")) | |
client.Do(request) | |
} | |
func main() { | |
// Open a file with one URL per line. | |
file, err := os.Open("urls.txt") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
urls := make(chan string, 1) | |
for i := 0; i < 300; i++ { | |
go func() { | |
for { | |
DoRequest(<-urls) | |
} | |
}() | |
} | |
i := 1 | |
scanner := bufio.NewScanner(file) | |
for scanner.Scan() { | |
path := scanner.Text() | |
fmt.Printf("%d %s\n", i, path) | |
urls <- path | |
i = i + 1 | |
} | |
if err := scanner.Err(); err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Waiting for final requests to finish...") | |
// This is hacky, but wait for the final requests to play out. | |
time.Sleep(5 * time.Minute) | |
fmt.Println("All done!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment