Skip to content

Instantly share code, notes, and snippets.

@jsha
Created April 6, 2016 22:25
Show Gist options
  • Save jsha/5190452f160b0b424ccb1beb7bb22d7a to your computer and use it in GitHub Desktop.
Save jsha/5190452f160b0b424ccb1beb7bb22d7a to your computer and use it in GitHub Desktop.

Revisions

  1. jsha created this gist Apr 6, 2016.
    39 changes: 39 additions & 0 deletions fetchtest.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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()
    }