Skip to content

Instantly share code, notes, and snippets.

@akovardin
Created December 11, 2018 21:37
Show Gist options
  • Select an option

  • Save akovardin/5eecccd438deed69e5acca24cb670361 to your computer and use it in GitHub Desktop.

Select an option

Save akovardin/5eecccd438deed69e5acca24cb670361 to your computer and use it in GitHub Desktop.

Revisions

  1. akovardin created this gist Dec 11, 2018.
    23 changes: 23 additions & 0 deletions download.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    func DownloadFile(filepath string, url string) error {
    // Get the data
    resp, err := http.Get(url)
    if err != nil {
    return err
    }
    defer resp.Body.Close()

    // Create the file
    out, err := os.Create(filepath)
    if err != nil {
    return err
    }
    defer out.Close()

    // Write the body to file
    _, err = io.Copy(out, resp.Body)
    if err != nil {
    return err
    }

    return nil
    }