Skip to content

Instantly share code, notes, and snippets.

@kougazhang
Last active February 24, 2022 01:55
Show Gist options
  • Save kougazhang/e6ec639347e319c1c5c21a6d5364b540 to your computer and use it in GitHub Desktop.
Save kougazhang/e6ec639347e319c1c5c21a6d5364b540 to your computer and use it in GitHub Desktop.
#golang #monitor #upyun
func TestUploadProgress(t *testing.T) {
progress := make(chan int, 1)
var src, upyunDest string
go func() {
var max, cur int
ticker := time.NewTicker(time.Second * 1)
defer ticker.Stop()
for {
select {
case <-ticker.C:
log.Infof("upload-progress %d/%d local %s to upyunDest %s ", cur, max, src, upyunDest)
case id, ok := <-progress:
if !ok {
log.Infof("exit")
return
}
if max == 0 {
max = id
} else {
cur = id
}
}
}
}()
progress <- 5
for i := 0; i < 5; i++ {
progress <- i
time.Sleep(time.Second)
}
close(progress)
time.Sleep(time.Second * 3)
fmt.Println("all finished")
}
@kougazhang
Copy link
Author

上传进度监控

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment