Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it in network IO #49

Open
duduxin opened this issue Oct 14, 2021 · 0 comments
Open

How to use it in network IO #49

duduxin opened this issue Oct 14, 2021 · 0 comments

Comments

@duduxin
Copy link

duduxin commented Oct 14, 2021

count := len(num)
bar1 := uiprogress.AddBar(count).AppendCompleted().PrependElapsed()
bar1.PrependFunc(func(b *uiprogress.Bar) string {
	return fmt.Sprintf("Task (%d/%d)", b.Current(), count)
})	

for bar1.Incr() {
//time.Sleep(time.Second * 5)
for i := 0; i < count; i++ {
s := rand.Float32()
time.Sleep(time.Second * time.Duration(s))
tsUrl := fmt.Sprintf("%s", baseUrl+num[i])
req, _ := http.NewRequest("GET", baseUrl, nil)
req.Header.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36")
resp, _ := client.Do(req)
body, _ := ioutil.ReadAll(resp.Body)

		if len(key) != 0 {
			data, _ = AesCrypt.AesDecrypt(body, key, iv)
		} else {
			data = []byte(string(body))
		}
		write.Write(data)


	}
	write.Flush()
}

This will always show the first progress bar after the request is sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant