2012-12-15 13 views
9

Vorrei ottenere l'URL e convertirlo in stringa. Devo seguente codice:Come convertire * url.URL in stringa in GO, Google App Engine

func getURL(w http.ResponseWriter, r *http.Request) { 
    var url string = r.URL 
} 

ottengo questo:

"non può convertire r.URL (tipo * url.URL) di tipo stringa"

Questo funziona bene :

fmt.Fprint(w,r.URL) 

Ma mi piacerebbe usarlo, non solo stamparlo.

Cosa devo fare?

risposta

17

Il tipo url.URL ha un metodo .String().

Prova questo.

func getURL(w http.ResponseWriter, r *http.Request) { 
    url := r.URL.String() 
} 

http://golang.org/pkg/net/url/#URL.String

+1

O ancora più breve: 'url: = r.URL.String()'? – jdi

+0

grazie mille. funziona: D – valaki

+0

@jdl: vero. Grazie per il suggerimento. :-) – Daniel