Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 17, 2021 18:31
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/8ee512e631f4e0d456e43fef2318ea8f to your computer and use it in GitHub Desktop.
Save parzibyte/8ee512e631f4e0d456e43fef2318ea8f to your computer and use it in GitHub Desktop.
func descargarArchivoDeInternet(url string) (string, error) {
/*
En este caso voy a descargar una imagen PNG
*/
nombreArchivoSalida := "imagen.png"
respuesta, err := http.Get(url)
if err != nil {
return "", err
}
defer respuesta.Body.Close()
archivoSalida, err := os.Create(nombreArchivoSalida)
if err != nil {
return "", err
}
defer archivoSalida.Close()
_, err = io.Copy(archivoSalida, respuesta.Body)
return nombreArchivoSalida, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment