How to set headers in HTTP GET request in Go?
Hello everyone! I'm new to Go and trying to make an HTTP GET request to an external API. I need to pass several headers, such as `Authorization` and `Content-Type`. I read the documentation but can't figure out how to do it correctly.
Here's my current code that doesn't work:
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.example.com/data"
// Trying to set headers
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer my-token")
req.Header.Set("Content-Type", "application/json")
// Executing the request
resp, err := http.Get(url) // This is the problem!
if err != nil {
```