本文整理匯總了Golang中github.com/cheggaaa/pb.ProgressBar.Total方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProgressBar.Total方法的具體用法?Golang ProgressBar.Total怎麽用?Golang ProgressBar.Total使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cheggaaa/pb.ProgressBar
的用法示例。
在下文中一共展示了ProgressBar.Total方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: uploadFileContents
// uploadFileContents does its best to upload the local file stored at
// localPath to the given *drive.File on Google Drive. (It assumes that
// the *drive.File has already been created.)
func uploadFileContents(localPath string, driveFile *gdrive.File, encrypt bool,
pb *pb.ProgressBar) error {
var iv []byte
var err error
if encrypt {
iv, err = getInitializationVector(driveFile)
if err != nil {
return fmt.Errorf("unable to get IV: %v", err)
}
}
for try := 0; ; try++ {
contentsReader, length, err :=
getFileContentsReaderForUpload(localPath, encrypt, iv)
if contentsReader != nil {
defer contentsReader.Close()
}
if err != nil {
return err
}
// Keep track of how many bytes are uploaded in case we fail
// part-way through and need to roll back the progress bar.
countingReader := &byteCountingReader{R: contentsReader}
// Also tee reads to the progress bar as they are done so that it
// stays in sync with how much data has been transmitted.
var uploadReader io.Reader
if pb != nil {
uploadReader = io.TeeReader(countingReader, pb)
} else {
uploadReader = countingReader
}
if length >= resumableUploadMinSize {
err = gd.UploadFileContentsResumable(driveFile, uploadReader, length)
} else {
err = gd.UploadFileContents(driveFile, uploadReader, length, try)
}
atomic.AddInt64(&stats.DiskReadBytes, countingReader.bytesRead)
if err == nil {
// Success!
atomic.AddInt64(&stats.DriveFilesUpdated, 1)
atomic.AddInt64(&stats.UploadBytes, length)
return nil
}
// The "progress" made so far on this file should be rolled back;
// if we don't do this, when retries happen, we end up going over
// 100% progress...
if pb != nil {
pb.Add64(-countingReader.bytesRead)
}
if re, ok := err.(gdrive.RetryHTTPTransmitError); ok && try < 5 {
debug.Printf("%s: got retry http error--retrying: %s",
localPath, re.Error())
} else {
debug.Printf("%s: giving up due to error: %v", localPath, err)
// We're giving up on this file, so subtract its length from
// what the progress bar is expecting.
if pb != nil {
pb.Total -= length
}
return err
}
}
}
示例2: runImport
//.........這裏部分代碼省略.........
case "mysql.dump":
f, err := ioutil.TempFile("", "mysql.dump")
if err != nil {
return fmt.Errorf("error creating db tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("error reading db dump: %s", err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking db tempfile: %s", err)
}
mysqlDump = f
uploadSize += header.Size
}
}
if app == nil {
return fmt.Errorf("missing app.json")
}
oldName := app.Name
if name := args.String["--name"]; name != "" {
app.Name = name
}
if err := client.CreateApp(app); err != nil {
return fmt.Errorf("error creating app: %s", err)
}
var bar *pb.ProgressBar
if !args.Bool["--quiet"] && uploadSize > 0 && term.IsTerminal(os.Stderr.Fd()) {
bar = pb.New(0)
bar.SetUnits(pb.U_BYTES)
bar.Total = uploadSize
bar.ShowSpeed = true
bar.Output = os.Stderr
bar.Start()
defer bar.Finish()
}
if pgDump != nil && release != nil {
res, err := client.ProvisionResource(&ct.ResourceReq{
ProviderID: "postgres",
Apps: []string{app.ID},
})
if err != nil {
return fmt.Errorf("error provisioning postgres resource: %s", err)
}
numResources++
if release.Env == nil {
release.Env = make(map[string]string, len(res.Env))
}
for k, v := range res.Env {
release.Env[k] = v
}
config, err := getPgRunConfig(client, app.ID, release)
if err != nil {
return fmt.Errorf("error getting postgres config: %s", err)
}
config.Stdin = pgDump
if bar != nil {
config.Stdin = bar.NewProxyReader(config.Stdin)
}
config.Exit = false
示例3: runImport
//.........這裏部分代碼省略.........
case "mysql.dump":
f, err := ioutil.TempFile("", "mysql.dump")
if err != nil {
return fmt.Errorf("error creating db tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("error reading db dump: %s", err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking db tempfile: %s", err)
}
mysqlDump = f
uploadSize += header.Size
}
}
if app == nil {
return fmt.Errorf("missing app.json")
}
oldName := app.Name
if name := args.String["--name"]; name != "" {
app.Name = name
}
if err := client.CreateApp(app); err != nil {
return fmt.Errorf("error creating app: %s", err)
}
var bar *pb.ProgressBar
if !args.Bool["--quiet"] && uploadSize > 0 && term.IsTerminal(os.Stderr.Fd()) {
bar = pb.New(0)
bar.SetUnits(pb.U_BYTES)
bar.Total = uploadSize
bar.ShowSpeed = true
bar.Output = os.Stderr
bar.Start()
defer bar.Finish()
}
if pgDump != nil && release != nil {
res, err := client.ProvisionResource(&ct.ResourceReq{
ProviderID: "postgres",
Apps: []string{app.ID},
})
if err != nil {
return fmt.Errorf("error provisioning postgres resource: %s", err)
}
numResources++
if release.Env == nil {
release.Env = make(map[string]string, len(res.Env))
}
for k, v := range res.Env {
release.Env[k] = v
}
config, err := getPgRunConfig(client, app.ID, release)
if err != nil {
return fmt.Errorf("error getting postgres config: %s", err)
}
config.Stdin = pgDump
if bar != nil {
config.Stdin = bar.NewProxyReader(config.Stdin)
}
config.Exit = false