file, err := os.Open("example.txt") if err != nil { log.Fatal(err) } defer file.Close() // ... do stuff with the file ...
resp, err := client.Get("http://example.com") if err != nil { log.Fatal(err) } defer resp.Body.Close() // ... do stuff with the response body ...In this example, we make a GET request using the `http.Client` type, which returns a `Response` struct containing the response body. We use a `defer` statement to automatically close the response body once we're done with it, using the `Close()` method provided by `io.Closer`.