Skip to content

Instantly share code, notes, and snippets.

/main.go Secret

Created December 7, 2014 02:30
Show Gist options
  • Save anonymous/4333543dfa0668034b89 to your computer and use it in GitHub Desktop.
Save anonymous/4333543dfa0668034b89 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sync"
)
type JSONSites struct {
Sites []string `json:"sites"`
}
// list of global top 100 sites by traffic
var SITES_FILE = "sites.json"
var MAX_CONCURRENT_REQUESTS = 10
func CheckSite(host string) (int, error) {
res, err := http.Get(fmt.Sprintf("http://%s", host))
if err != nil {
return -1, err
}
return res.StatusCode, nil
}
func main() {
var wg sync.WaitGroup
sites_json, _ := ioutil.ReadFile(SITES_FILE)
s := &JSONSites{}
if err := json.Unmarshal(sites_json, &s); err != nil {
panic(err)
}
for _, site := range s.Sites {
wg.Add(1)
go func(host string) {
defer wg.Done()
status, err := CheckSite(host)
if err != nil {
fmt.Println("ERROR:", err)
} else {
fmt.Printf("%s: %d\n", host, status)
}
}(site)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment