Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert *url.URL to string in GO, Google App Engine

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?

like image 315
valaki Avatar asked Dec 15 '12 21:12

valaki


1 Answers

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

like image 79
Daniel Avatar answered Oct 01 '22 21:10

Daniel