In chapter 8, Talking to REST APIs, section Testing the REST API Server, the following snippet in server_test.go
triggers a warning from go vet
:
r, err := http.Get(url + tc.path)
defer r.Body.Close()
if err != nil {
t.Error(err)
}
‘using r before cheking for errors’. To clear this warning, we must move the defer
statement after the error check like this:
r, err := http.Get(url + tc.path)
if err != nil {
t.Error(err)
}
defer r.Body.Close()