Skip to content

Instantly share code, notes, and snippets.

@juliocabrera820
Created April 5, 2020 02:53
Show Gist options
  • Save juliocabrera820/01bb4999e9e74c6b213813b73ac2212a to your computer and use it in GitHub Desktop.
Save juliocabrera820/01bb4999e9e74c6b213813b73ac2212a to your computer and use it in GitHub Desktop.
URI y Query
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))
}

http://localhost:3000/?nombre=sarah

URI

  • Para obtener la URI se usa el método URL de la petición
  • Mostrar en consola con el método Println

RawQuery

  • Usar el método RawQuery

Valor de la Query

  • Usar el método Query()

Obtener valor del parámetro

  • Usar el método GET para obtener el valor de nombre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment