-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
33 lines (26 loc) · 1.03 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"net/http"
"sync"
"github.com/lkendrickd/concurrency/urlchecker"
)
// ##### NOTE: Drop in any of the example code from the respective directories
// markdown file example to see the output of the code in the main function. There are also table
// driven tests in the respective directories that can be run with `go test`.
func main() {
// List of URLs to check
urls := []string{
"http://api.open-notify.org/astros.json", // This URL returns the number of astronauts currently in space.
"https://catfact.ninja/fact", // This URL returns a random cat fact.
}
// Create a new Checker instance
client := &http.Client{} // A client is needed to call the URLs
wg := &sync.WaitGroup{} // A waitgroup is needed to wait for all goroutines to finish
checker := urlchecker.New(client, urls, wg) // Create a new checker instance
// Perform the checks
checker.Check()
// Retrieve and print the results
for result := range checker.Results() {
println(result)
}
}