title: How to add URL query parameters to HTTP GET request?
body: <p>I am trying to add a query parameter to a HTTP GET request but somehow methods pointed out on SO (e.g. <a href="https://stackoverflow.com/questions/19253469/make-a-url-encoded-post-request-using-http-newrequest">here</a>) don't work.</p>
  
  <p>I have the following piece of code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
      "net/http"
  )
  
  func main() {
      req, err := http.NewRequest("GET", "/callback", nil)
      req.URL.Query().Add("code", "0xdead 0xbeef")
      req.URL.Query().Set("code", "0xdead 0xbeef")
      // this doesn't help
      //req.URL.RawQuery = req.URL.Query().Encode()
  
      if err != nil {
          log.Fatal(err)
      }
  
      fmt.Printf("URL      %+v\n", req.URL)
      fmt.Printf("RawQuery %+v\n", req.URL.RawQuery)
      fmt.Printf("Query    %+v\n", req.URL.Query())
  }
  </code></pre>
  
  <p>which prints:</p>
  
  <pre><code>URL      /callback
  RawQuery 
  Query    map[]
  </code></pre>
  
  <p>Any suggestions on how to achieve this?</p>
  
  <p>Playground example: <a href="https://play.golang.org/p/SYN4yNbCmo" rel="noreferrer">https://play.golang.org/p/SYN4yNbCmo</a></p>