I am looking for go code to fetch url and in most of the cases this the code for fetching url on go :
func main() {
for _, url := range os.Args[1:] {
resp, err := http.Get(url)
if err != nil {
fmt.Fprintf(os.Stderr, "fetch: %v
", err)
os.Exit(1)
}
b, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "fetch: reading %s: %v
", url, err)
os.Exit(1)
}
fmt.Printf("%s", b)
}
}
my question why needed here resp.Body.Close() and whay this exactly doing ?