Skip to content

Instantly share code, notes, and snippets.

@Pushplaybang
Created October 14, 2018 11:35
Show Gist options
  • Save Pushplaybang/f17044fcf23bce6ba1050a0d45ebacab to your computer and use it in GitHub Desktop.
Save Pushplaybang/f17044fcf23bce6ba1050a0d45ebacab to your computer and use it in GitHub Desktop.
very simple example of concurrency in go.
package main
import (
"fmt"
"net/http"
)
func main() {
links := []string{
"http://golang.org",
"http://google.com",
"http://stackoverflow.com",
"http://facebook.com",
"http://amazon.com",
"http://netflix.com",
}
c := make(chan string)
for _, link := range links {
go checkLink(link, c)
}
for i := 0; i < len(links); i++ {
fmt.Println(<- c)
}
}
func checkLink(link string, c chan string) {
_, err := http.Get(link)
if err != nil {
fmt.Println(link, "seems to be down.")
c <- "might be down I think"
return
}
fmt.Println(link, "looks good.")
c <- "yup, thats good."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment