Skip to content

Instantly share code, notes, and snippets.

@imjasonh
Last active October 28, 2021 06:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imjasonh/eef12b905d2367457990 to your computer and use it in GitHub Desktop.
Save imjasonh/eef12b905d2367457990 to your computer and use it in GitHub Desktop.
Playing around with github.com/cheggaaa/pb
package main
import (
"flag"
"io/ioutil"
"log"
"net/http"
"strconv"
"github.com/cheggaaa/pb"
)
var url = flag.String("url", "", "URL to get")
func main() {
flag.Parse()
resp, err := http.Get(*url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
l, err := strconv.Atoi(resp.Header.Get("Content-Length"))
if err != nil {
log.Fatal("no content-length")
}
b := pb.New(l).SetUnits(pb.U_BYTES)
b.ShowSpeed = true
b.Start()
ioutil.ReadAll(b.NewProxyReader(resp.Body))
b.Finish()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment