Last active
December 17, 2015 22:49
-
-
Save shingara/5684521 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 ( | |
"os" | |
"fmt" | |
"github.com/shingara/goup/request" | |
) | |
func main() { | |
urls := make(chan string, 100) | |
status := make(chan int, 100) | |
go request.Req(urls, status) | |
go request.Req(urls, status) | |
go request.Req(urls, status) | |
for w := 1; w <= 50; w++ { | |
fmt.Println("send url to goroutine") | |
urls <- os.Args[1] | |
} | |
fmt.Println("close urls") | |
close(urls) | |
for statut := range status { | |
fmt.Printf("status : %d\n", statut) | |
} | |
} |
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 request | |
import( | |
"fmt" | |
"net/http" | |
"log" | |
) | |
func Req(urls chan string, status chan int) { | |
for url := range urls { | |
fmt.Printf("launch request on %s\n", url) | |
resp, err := http.Get(url) | |
defer resp.Body.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
status <- resp.StatusCode | |
} | |
close(status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment