RequestURI returns the encoded path?query or opaque?query string that would be used in an HTTP request for u.
package main import ( "fmt" "log" "net/url" ) func main() { u, err := url.Parse("https://example.org/path?foo=bar") if err != nil { log.Fatal(err) } fmt.Println(u.RequestURI()) }