You need to URL-Encode your query string, like this:
package main
import (
"fmt"
"net/url"
)
func main() {
query := make(url.Values)
query.Add("domain", "example.com?foo=bar")
fmt.Println(query.Encode())
}
Which outputs domain=example.com%3Ffoo%3Dbar
.
You can set that string as a RawQuery
of an url.URL
value and if you then access the query like you did, it will have the correct value.
If the URL is correctly encoded then you should be able to run the following code with your URL value and get the correct result:
package main
import (
"fmt"
"net/url"
)
func main() {
query := make(url.Values)
query.Add("domain", "example.com?foo=bar&abc=123&jkl=qwe")
url := &url.URL{RawQuery: query.Encode(), Host: "domain.com", Scheme: "http"}
fmt.Println(url.String())
abc := url.Query().Get("domain")
fmt.Println(abc)
}
This prints:
http://domain.com?domain=example.com%3Ffoo%3Dbar%26abc%3D123%26jkl%3Dqwe
(the complete URI with the encoded parameter called "domain")
example.com?foo=bar&abc=123&jkl=qwe
(the decoded value of said parameter)