How to get HTTP response body as a string in Go?
Hi everyone! I just started learning Go and ran into a problem when working with HTTP requests. I need to send a GET request to an external API and get the response as a plain string, so I can then process it — for example, parse JSON or just output it to a log.
I wrote this code:
```go
resp, err := http.Get("https://api.example.com/data")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Println(resp) // prints something like &{200 OK 200 ...}
```
The problem is that `resp` is a `*http.Response` struct, not a string. I tried accessing `resp.Body`, but it's an `io.ReadCloser`, and I don't know how to get the text from it. In other languages (Python, JavaScript) I'm used to just reading `response.text` or `response.body`, but here it's more complicated.
I've read