Last active
October 28, 2021 06:21
-
-
Save imjasonh/eef12b905d2367457990 to your computer and use it in GitHub Desktop.
Playing around with github.com/cheggaaa/pb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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