github.com/iikira/iikira-go-utils@v0.0.0-20230610031953-f2cb11cde33a/requester/uploader/example.go (about) 1 package uploader 2 3 import ( 4 "fmt" 5 "github.com/iikira/iikira-go-utils/requester/rio" 6 "github.com/iikira/iikira-go-utils/utils/converter" 7 ) 8 9 // DoUpload 执行上传 10 func DoUpload(uploadURL string, readerlen64 rio.ReaderLen64, checkFunc CheckFunc) { 11 u := NewUploader(uploadURL, readerlen64) 12 u.SetCheckFunc(checkFunc) 13 14 exitChan := make(chan struct{}) 15 16 u.OnExecute(func() { 17 statusChan := u.GetStatusChan() 18 for { 19 select { 20 case <-exitChan: 21 return 22 case v, ok := <-statusChan: 23 if !ok { 24 return 25 } 26 27 fmt.Printf("\r ↑ %s/%s %s/s in %s ............", 28 converter.ConvertFileSize(v.Uploaded(), 2), 29 converter.ConvertFileSize(v.TotalSize(), 2), 30 converter.ConvertFileSize(v.SpeedsPerSecond(), 2), 31 v.TimeElapsed(), 32 ) 33 } 34 } 35 }) 36 37 u.Execute() 38 close(exitChan) 39 40 return 41 }