-
-
Save anonymous/4333543dfa0668034b89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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