golang http panic: runtime error: invalid memory address or nil pointer dereference
下面代码将报错,提示panic: runtime error: invalid memory address or nil pointer dereference
resp, _ := http.Get(link.ImgUrl)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
正确的应是, defer resp.Body.Close()
应在 ioutil.ReadAll
之后
resp, _ := http.Get(link.ImgUrl)
body, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
菜鸟总结 0.0