How to Set Headers on an HTTP Request in Go

Web
Set HTTP request headers in Go by calling the Header.Set method on the Request object before executing the request.

Use the Header.Set method on the Request object to add or update headers before sending the request.

req, _ := http.NewRequest("GET", "https://example.com", nil)
req.Header.Set("Authorization", "Bearer token123")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)