Skip to content

Instantly share code, notes, and snippets.

@jsha
Created April 6, 2016 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsha/5190452f160b0b424ccb1beb7bb22d7a to your computer and use it in GitHub Desktop.
Save jsha/5190452f160b0b424ccb1beb7bb22d7a to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"flag"
"fmt"
"net/http"
"os"
"sync"
)
var parallel = flag.Int("parallel", 5, "parallel requests")
func main() {
flag.Parse()
names := make(chan string)
wg := sync.WaitGroup{}
for i := 0; i < *parallel; i++ {
go func() {
for name := range names {
_, err := http.Get("https://" + name + "/")
if err != nil {
fmt.Printf("%s: %s\n", name, err)
}
wg.Done()
}
}()
}
reader := bufio.NewScanner(os.Stdin)
for reader.Scan() {
name := reader.Text()
if name != "" {
wg.Add(1)
names <- name
}
}
close(names)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment