Skip to content

Instantly share code, notes, and snippets.

@jkakar
Last active April 9, 2016 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkakar/3ff610ad1fb7a8695865f804ef369a15 to your computer and use it in GitHub Desktop.
Save jkakar/3ff610ad1fb7a8695865f804ef369a15 to your computer and use it in GitHub Desktop.
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