I would like to get the URL and convert it to string. I have to following code:
func getURL(w http.ResponseWriter, r *http.Request) {
var url string = r.URL
}
I get this:
"cannot convert r.URL (type *url.URL) to type string"
This is working well:
fmt.Fprint(w,r.URL)
But I would like to use it, not just print it.
What should I do?
The url.URL type has a .String() method.
Try this.
func getURL(w http.ResponseWriter, r *http.Request) {
url := r.URL.String()
}
http://golang.org/pkg/net/url/#URL.String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With