summaryrefslogtreecommitdiff
path: root/check_websites.go
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-12-08 12:51:18 -0700
committermo khan <mo.khan@gmail.com>2019-12-08 12:51:18 -0700
commit4748519fd9cb750de0d1dd22907e4b9af6fb81c2 (patch)
tree60cfce864e22e460e4578853a244442e194efdb3 /check_websites.go
parente67ebfe8bfca02403bffa9399043220e64323dca (diff)
learn about go routines
Diffstat (limited to 'check_websites.go')
-rw-r--r--check_websites.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/check_websites.go b/check_websites.go
new file mode 100644
index 0000000..ad7b0e5
--- /dev/null
+++ b/check_websites.go
@@ -0,0 +1,25 @@
+package main
+
+type WebsiteChecker func(string) bool
+type result struct {
+ string
+ bool
+}
+
+func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
+ results := make(map[string]bool)
+ resultChannel := make(chan result)
+
+ for _, url := range urls {
+ go func(u string) {
+ resultChannel <- result{u, wc(u)}
+ }(url)
+ }
+
+ for i := 0; i < len(urls); i++ {
+ result := <-resultChannel
+ results[result.string] = result.bool
+ }
+
+ return results
+}