mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 06:23:59 +08:00
example code from: https://sites.google.com/site/thewaytogo2012/Downhome/Topic3/code_examples.zip
31 lines
581 B
Go
31 lines
581 B
Go
// poll_url.go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
var urls = []string{
|
|
"http://www.google.com/",
|
|
"http://golang.org/",
|
|
"http://blog.golang.org/",
|
|
}
|
|
|
|
func main() {
|
|
// Execute an HTTP HEAD request for all url's
|
|
// and returns the HTTP status string or an error string.
|
|
for _, url := range urls {
|
|
resp, err := http.Head(url)
|
|
if err != nil {
|
|
fmt.Println("Error", url, err)
|
|
}
|
|
fmt.Print(url, ": ", resp.Status)
|
|
}
|
|
}
|
|
/* Output:
|
|
http://www.google.com/ : 302 Found
|
|
http://golang.org/ : 200 OK
|
|
http://blog.golang.org/ : 200 OK
|
|
*/
|