在Go中,我有一些http响应,有时我忘了打电话:
resp.Body.Close()
在这种情况下会发生什么?会有内存泄漏吗?defer resp.Body.Close()
获取响应对象后立即放入是否安全?
client := http.DefaultClient
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
return nil, err
}
如果有错误,可能resp
还是resp.Body
无效怎么办?