Last active
August 29, 2015 13:56
-
-
Save agocs/9164543 to your computer and use it in GitHub Desktop.
A dumb http client that GETs a few different URLs.
This file contains 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 "net/http" | |
import "fmt" | |
import "time" | |
type http_req struct { | |
req_time time.Duration | |
url string | |
status string | |
} | |
var http_times = make(chan http_req) | |
func main() { | |
start := time.Now() | |
go bother("http://example.com") | |
go bother("http://tumblr.com") | |
go bother("http://yahoo.com") | |
go bother("http://jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com") | |
go bother("http://penny-arcade.com") | |
go bother("http://google.com") | |
go bother("http://taco-mac.com") | |
go bother("http://apple.com") | |
go bother("http://python.org") | |
go bother("http://mitsubishi.com") | |
go bother("http://toyota.com") | |
go bother("http://ford.com") | |
go bother("http://chevrolet.com") | |
go bother("http://audi.com") | |
go bother("http://subaru.com") | |
go bother("http://bmw.com") | |
go bother("http://honda.com") | |
go bother("http://motorola.com") | |
go bother("http://cingular.com") | |
go bother("http://att.com") | |
go bother("http://ibm.com") | |
go bother("http://compaq.com") | |
go bother("http://dell.com") | |
go bother("http://cdw.com") | |
for i := 0; i < 24; i++ { | |
fmt.Println(<-http_times) | |
} | |
fmt.Println("I have returned.") | |
fmt.Println(time.Since(start)) | |
} | |
func bother(who string) { | |
start := time.Now() | |
resp, err := http.Get(who) | |
if err != nil { | |
http_times <- http_req{time.Since(start), who, err.Error()} | |
} else { | |
http_times <- http_req{time.Since(start), who, resp.Status} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cagocs:dumbclient christopheragocs$ go run dumbclient.go
{9364420 http://jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com Get http://jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com: dial tcp: lookup jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com: no such host}
{719365213 http://taco-mac.com Get http://taco-mac.com/?3e3ea140: EOF}
{983039621 http://example.com 200 OK}
{1219575832 http://penny-arcade.com 200 OK}
{1449042678 http://python.org 200 OK}
{1807195478 http://honda.com 200 OK}
{1847580758 http://mitsubishi.com 403 Forbidden}
{1947187626 http://subaru.com 200 OK}
{2237452752 http://compaq.com 200 OK}
{2428606022 http://google.com 200 OK}
{2466545761 http://cdw.com 200 OK}
{2922516086 http://apple.com 200 OK}
{2945832716 http://ford.com 200 OK}
{3248721581 http://bmw.com 200 OK}
{3335337918 http://chevrolet.com 200 OK}
{3879777276 http://att.com 200 OK}
{4075555273 http://dell.com 200 OK}
{4834800209 http://motorola.com 200 OK}
{6207428818 http://audi.com 200 OK}
{6322143521 http://ibm.com 200 OK}
{6951210760 http://tumblr.com 200 OK}
{7240776729 http://yahoo.com 200 OK}
{8171975140 http://toyota.com 200 OK}
{8251384868 http://cingular.com 200 OK}
I have returned.
8.251663736s