Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 30, 2019 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3b70589e56f1314f6a58c97aee0cc6dc to your computer and use it in GitHub Desktop.
Save parzibyte/3b70589e56f1314f6a58c97aee0cc6dc to your computer and use it in GitHub Desktop.
enrutador.HandleFunc("/usuario/{id}", obtenerUsuarioPorId).Methods("GET")
func obtenerUsuarioPorId(respuesta http.ResponseWriter, peticion *http.Request) {
variablesDePeticion := mux.Vars(peticion)
// El id viene como cadena, hay que convertirlo a entero de 32 bits
// Aquí "id" es la variable que indicamos en la ruta
idUsuarioBuscado, err := strconv.Atoi(variablesDePeticion["id"])
// TODO: hacer algo con la variable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment