add missing code example of chapter 15.3 (#678)

example code from:
https://sites.google.com/site/thewaytogo2012/Downhome/Topic3/code_examples.zip
This commit is contained in:
marjune
2019-07-16 10:57:06 +08:00
committed by ᴊ. ᴄʜᴇɴ
parent 9865ae64a9
commit 00e4346204
4 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
// 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)
}
}