📌  相关文章
📜  下载文件 - Go 编程语言 - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:45:01.192000             🧑  作者: Mango

代码示例1
func downloadFile(path string, url string) (error) {

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

  // Get the data
  resp, err := http.Get(url)
  if err != nil { return err }
  defer resp.Body.Close()

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

  return nil
}