http://localhost:3000/?nombre=sarah
- Para obtener la
URI
se usa el métodoURL
de la petición - Mostrar en consola con el método
Println
- Usar el método
RawQuery
- Usar el método
Query()
- Usar el método
GET
para obtener el valor denombre
package main | |
import ( | |
"net/http" | |
"log" | |
"fmt" | |
) | |
func main() { | |
http.HandleFunc("/", func (w http.ResponseWriter,r *http.Request){ | |
fmt.Println(r.URL.Query().Get("nombre")) | |
}) | |
log.Fatal(http.ListenAndServe(":3000",nil)) | |
} |
package main | |
import ( | |
"net/http" | |
"log" | |
"fmt" | |
) | |
func main() { | |
http.HandleFunc("/", func (w http.ResponseWriter,r *http.Request){ | |
fmt.Println(r.URL.Query()) | |
}) | |
log.Fatal(http.ListenAndServe(":3000",nil)) | |
} |
package main | |
import ( | |
"net/http" | |
"log" | |
"fmt" | |
) | |
func main() { | |
http.HandleFunc("/", func (w http.ResponseWriter,r *http.Request){ | |
fmt.Println(r.URL.RawQuery) | |
}) | |
log.Fatal(http.ListenAndServe(":3000",nil)) | |
} |
package main | |
import ( | |
"net/http" | |
"log" | |
"fmt" | |
) | |
func main() { | |
http.HandleFunc("/", func (w http.ResponseWriter,r *http.Request){ | |
fmt.Println(r.URL) | |
}) | |
log.Fatal(http.ListenAndServe(":3000",nil)) | |
} |