Last active
February 24, 2022 01:55
-
-
Save kougazhang/e6ec639347e319c1c5c21a6d5364b540 to your computer and use it in GitHub Desktop.
#golang #monitor #upyun
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
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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
上传进度监控