Skip to content

Instantly share code, notes, and snippets.

@jkakar
Last active Apr 9, 2016
Embed
What would you like to do?
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