<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Save on Gopher Coding</title><link>https://gophercoding.com/tags/save/</link><description>Recent content in Save on Gopher Coding</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sun, 02 Apr 2023 12:13:48 +0100</lastBuildDate><atom:link href="https://gophercoding.com/tags/save/index.xml" rel="self" type="application/rss+xml"/><item><title>Download a File from a URL</title><link>https://gophercoding.com/download-a-file/</link><pubDate>Sun, 18 Sep 2022 08:00:00 +0000</pubDate><guid>https://gophercoding.com/download-a-file/</guid><description>&lt;p>This post shows how you can &lt;strong>download a file&lt;/strong> in Go from a URL. We use the std lib (standard library) &lt;code>http.Get()&lt;/code> [&lt;a href="https://pkg.go.dev/net/http#Client.Get">docs&lt;/a>] and &lt;code>io.Copy()&lt;/code> [&lt;a href="https://pkg.go.dev/io#Copy">docs&lt;/a>] functions to help us with this. This function should be &lt;em>efficient&lt;/em> as it will stream the data into the file, as opposed to downloading it all into memory, then to file.&lt;/p>
&lt;p>The file will be saved in the same directory as your program.&lt;/p>
&lt;p>We also show &lt;a href="#alternative-filename">an alternative&lt;/a> below if you want to take the filename from the URL.&lt;/p></description></item></channel></rss>