mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
example code from: https://sites.google.com/site/thewaytogo2012/Downhome/Topic3/code_examples.zip
24 lines
358 B
Go
24 lines
358 B
Go
// httpfetch.go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"io/ioutil"
|
|
"log"
|
|
)
|
|
|
|
func main() {
|
|
res, err := http.Get("http://www.google.com")
|
|
CheckError(err)
|
|
data, err := ioutil.ReadAll(res.Body)
|
|
CheckError(err)
|
|
fmt.Printf("Got: %q", string(data))
|
|
}
|
|
|
|
func CheckError(err error) {
|
|
if err != nil {
|
|
log.Fatalf("Get: %v", err)
|
|
}
|
|
}
|