]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix misplaced defer and example
authorDave Cheney <dave@cheney.net>
Tue, 21 Aug 2012 01:46:07 +0000 (11:46 +1000)
committerDave Cheney <dave@cheney.net>
Tue, 21 Aug 2012 01:46:07 +0000 (11:46 +1000)
Moves the defer (again).

Also, correct the example documentation to match.

R=r, robert.hencke, iant, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/6458158

src/pkg/net/http/example_test.go
src/pkg/net/http/transport_test.go

index ec814407ddb2bddc97cb349b57b003ed60f0cec5..22073eaf7aa88fba065e64f96d4bfcfdd17adcec 100644 (file)
@@ -43,10 +43,10 @@ func ExampleGet() {
                log.Fatal(err)
        }
        robots, err := ioutil.ReadAll(res.Body)
+       res.Body.Close()
        if err != nil {
                log.Fatal(err)
        }
-       res.Body.Close()
        fmt.Printf("%s", robots)
 }
 
index 14465727c2528774f2cfa926b90033ece11dc69a..e4072e88fed3af54e08fa5652d9cd125a44ca617 100644 (file)
@@ -160,11 +160,11 @@ func TestTransportConnectionCloseOnResponse(t *testing.T) {
                        if err != nil {
                                t.Fatalf("error in connectionClose=%v, req #%d, Do: %v", connectionClose, n, err)
                        }
+                       defer res.Body.Close()
                        body, err := ioutil.ReadAll(res.Body)
                        if err != nil {
                                t.Fatalf("error in connectionClose=%v, req #%d, ReadAll: %v", connectionClose, n, err)
                        }
-                       defer res.Body.Close()
                        return string(body)
                }