LEFT | RIGHT |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package http_test | 5 package http_test |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "io/ioutil" | 9 "io/ioutil" |
10 "log" | 10 "log" |
(...skipping 25 matching lines...) Expand all Loading... |
36 bufrw.Flush() | 36 bufrw.Flush() |
37 }) | 37 }) |
38 } | 38 } |
39 | 39 |
40 func ExampleGet() { | 40 func ExampleGet() { |
41 res, err := http.Get("http://www.google.com/robots.txt") | 41 res, err := http.Get("http://www.google.com/robots.txt") |
42 if err != nil { | 42 if err != nil { |
43 log.Fatal(err) | 43 log.Fatal(err) |
44 } | 44 } |
45 robots, err := ioutil.ReadAll(res.Body) | 45 robots, err := ioutil.ReadAll(res.Body) |
46 » defer res.Body.Close() | 46 » res.Body.Close() |
47 if err != nil { | 47 if err != nil { |
48 log.Fatal(err) | 48 log.Fatal(err) |
49 } | 49 } |
50 fmt.Printf("%s", robots) | 50 fmt.Printf("%s", robots) |
51 } | 51 } |
52 | 52 |
53 func ExampleFileServer() { | 53 func ExampleFileServer() { |
54 // we use StripPrefix so that /tmpfiles/somefile will access /tmp/somefi
le | 54 // we use StripPrefix so that /tmpfiles/somefile will access /tmp/somefi
le |
55 http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer
(http.Dir("/tmp")))) | 55 http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer
(http.Dir("/tmp")))) |
56 } | 56 } |
LEFT | RIGHT |