HTTP file download progress bar in Go

Viewed 624

I saw a post a while ago with a progress bar function using the github.com/cheggaaa/pb package along the lines of:

func download(destinationPath, downloadUrl string) error {
    tempDestinationPath := destinationPath + ".tmp"
    request, err := http.NewRequest("GET", downloadUrl, nil)
...
    var progressBar *pb.ProgressBar
    contentLength := strconv.Atoi(request.Header.Get("Content-Length"))
...
    io.MultiWriter(writer, progressBar)
...

I used it in some code, but I lost that code a few days ago and I cannot find this function anywhere again. If anyone could help me at least rewrite it, I'd be very grateful. It used io.Writer and io.MultiWriter to write the data both to a file and increment the progress bar at once. Thankk you for any help!

1 Answers
Related