tiktok-dl/utils/downloadFile.go
Pijus Kamandulis 70c3faf17e Use go modules
2020-04-12 03:22:00 +03:00

27 lines
516 B
Go

package utils
import (
"io"
"net/http"
"os"
checkErr "github.com/pikami/tiktok-dl/utils/checkErr"
)
// DownloadFile - Downloads content from `url` and stores it in `outputPath`
func DownloadFile(outputPath string, url string) {
// Get the data
resp, err := http.Get(url)
checkErr.CheckErr(err)
defer resp.Body.Close()
// Create the file
out, err := os.Create(outputPath)
checkErr.CheckErr(err)
defer out.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
checkErr.CheckErr(err)
}