在Golang我有一些http响应,我有时忘记打电话:
resp.Body.Close()
Run Code Online (Sandbox Code Playgroud)
在这种情况下会发生什么?会有内存泄漏吗?defer resp.Body.Close()获取响应对象后立即放入是否安全?
client := http.DefaultClient
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
return nil, err
}
Run Code Online (Sandbox Code Playgroud)
如果有错误怎么办,可能resp或者resp.Body是零?
go ×1