Skip to content

Instantly share code, notes, and snippets.

@gsingharoy
Created April 22, 2018 16:26
Show Gist options
  • Save gsingharoy/68be84cf78b929021f3c0f54e69eb67e to your computer and use it in GitHub Desktop.
Save gsingharoy/68be84cf78b929021f3c0f54e69eb67e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"sync"
)
func main() {
// A slice of sample websites
urls := []string{
"https://www.easyjet.com/",
"https://www.skyscanner.de/",
"https://www.ryanair.com",
"https://wizzair.com/",
"https://www.swiss.com/",
}
var wg sync.WaitGroup
for _, u := range urls {
// Increment the wait group counter
wg.Add(1)
go func(url string) {
// Decrement the counter when the go routine completes
defer wg.Done()
// Call the function check
checkUrl(url)
}(u)
}
// Wait for all the checkWebsite calls to finish
wg.Wait()
}
//checks and prints a message if a website is up or down
func checkUrl(url string) {
_, err := http.Get(url)
if err != nil {
fmt.Println(url, "is down !!!")
return
}
fmt.Println(url, "is up and running.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment