本文整理匯總了Golang中github.com/cheggaaa/pb.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Example_multiple
func Example_multiple() {
// create bars
first := pb.New(200).Prefix("First ")
second := pb.New(200).Prefix("Second ")
third := pb.New(200).Prefix("Third ")
// start pool
pool, err := pb.StartPool(first, second, third)
if err != nil {
panic(err)
}
// update bars
wg := new(sync.WaitGroup)
for _, bar := range []*pb.ProgressBar{first, second, third} {
wg.Add(1)
go func(cb *pb.ProgressBar) {
for n := 0; n < 200; n++ {
cb.Increment()
time.Sleep(time.Millisecond * time.Duration(rand.Intn(100)))
}
cb.Finish()
wg.Done()
}(bar)
}
wg.Wait()
// close pool
pool.Stop()
}
示例2: SetupLog
//SetupLog sets up initial ConnectionLog
func SetupLog(length, noOfConn int) error {
connLog.stats = make([]ConnectionStat, noOfConn)
barArray := make([]*pb.ProgressBar, noOfConn+1)
lenSub := length / noOfConn
for i := 0; i < noOfConn; i++ {
fileBegin := lenSub * i
fileEnd := lenSub * (i + 1)
if i == noOfConn-1 {
fileEnd = length
}
bar := pb.New(fileEnd - fileBegin).Prefix("Connection " + strconv.Itoa(i+1) + " ")
customizeBar(bar)
connLog.stats[i] = ConnectionStat{connectionIndex: i, pbar: bar}
barArray[i] = bar
}
bar := pb.New(length).Prefix("Total ")
customizeBar(bar)
connLog.totalbar = bar
barArray[noOfConn] = bar
var err error
connLog.pool, err = pb.StartPool(barArray...)
if err != nil {
return err
}
return nil
}
示例3: Update
// Update replaces the inode of the current executable with the latest version
// n.b. this won't work on Windows
func (u *Updater) Update() error {
u.l.Infoln("Downloading version", u.ServerVersion.Version)
werckerPath, err := filepath.Abs(os.Args[0])
if err != nil {
return err
}
// Put new version in tempfile in parent directory.
temp, err := ioutil.TempFile(filepath.Dir(werckerPath), fmt.Sprintf(".%s-", u.ServerVersion.Version))
if err != nil {
return err
}
defer temp.Close()
newVersion, err := http.Get(u.DownloadURL())
if err != nil {
return err
}
defer newVersion.Body.Close()
bar := pb.New(int(newVersion.ContentLength)).SetUnits(pb.U_BYTES)
bar.Start()
writer := io.MultiWriter(temp, bar)
_, err = io.Copy(writer, newVersion.Body)
if err != nil {
return err
}
temp.Chmod(0755)
return os.Rename(temp.Name(), werckerPath)
}
示例4: downloader
func downloader(uri string, file string) {
var log = logrus.New()
log.Formatter = new(logrus.JSONFormatter)
log.Debug("creating file.")
outFile, err := os.Create(file)
if err != nil {
os.Exit(1)
}
client := &http.Client{}
log.Debugf("new request for %+v", uri)
req, err := http.NewRequest("GET", uri, nil)
log.Debug("request initiated.")
resp, err := client.Do(req)
//progress bar
header := resp.ContentLength
bar := pb.New(int(header)).SetUnits(pb.U_BYTES)
bar.Start()
reader := bar.NewProxyReader(resp.Body)
if err != nil {
panic(err)
}
// not closing reader as the NewProxyReader exits for me.
log.Debugf("copying response data to %+v", file)
io.Copy(outFile, reader)
os.Exit(0)
}
示例5: runPgRestore
func runPgRestore(args *docopt.Args, client controller.Client, config *runConfig) error {
config.Stdin = os.Stdin
var size int64
if filename := args.String["--file"]; filename != "" {
f, err := os.Open(filename)
if err != nil {
return err
}
defer f.Close()
stat, err := f.Stat()
if err != nil {
return err
}
size = stat.Size()
config.Stdin = f
}
if !args.Bool["--quiet"] && term.IsTerminal(os.Stderr.Fd()) {
bar := pb.New(0)
bar.SetUnits(pb.U_BYTES)
if size > 0 {
bar.Total = size
} else {
bar.ShowBar = false
}
bar.ShowSpeed = true
bar.Output = os.Stderr
bar.Start()
defer bar.Finish()
config.Stdin = bar.NewProxyReader(config.Stdin)
}
return pgRestore(client, config)
}
示例6: newPb
func newPb(size int) (bar *pb.ProgressBar) {
bar = pb.New(size)
bar.SetRefreshRate(time.Millisecond)
bar.ShowSpeed = true
bar.Start()
return
}
示例7: share
func share(srv *drive.Service, accountFrom string, accountTo string) error {
// List all files and folders
files, err := findAllFilesFrom(srv, accountFrom)
if err != nil {
return err
}
fmt.Printf("Found: %d files or directories\n", len(files))
// Progress bar
bar := pb.New(len(files))
bar.SetRefreshRate(time.Second)
bar.Start()
for _, file := range files {
bar.Increment()
err := shareFile(srv, file, accountTo)
if err != nil {
return err
}
}
bar.FinishPrint("Done.")
// Everything is OK
return nil
}
示例8: imageDownloader
func imageDownloader(uri string, filename string, wg *sync.WaitGroup) {
defer wg.Done()
tokens := strings.Split(uri, "/")
fileName := tokens[len(tokens)-1]
outFile, err := os.Create(fileName)
if err != nil {
fmt.Println(err)
}
client := &http.Client{}
req, err := http.NewRequest("GET", uri, nil)
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
header := resp.ContentLength
bar := pb.New(int(header)).SetUnits(pb.U_BYTES)
bar.SetRefreshRate(time.Millisecond)
// bar.Start()
rd := bar.NewProxyReader(resp.Body)
// and copy from reader
io.Copy(outFile, rd)
if err != nil {
fmt.Println(err)
}
}
示例9: runRedisDump
func runRedisDump(args *docopt.Args, client controller.Client, config *runConfig) error {
config.Stdout = os.Stdout
if filename := args.String["--file"]; filename != "" {
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
config.Stdout = f
}
if !args.Bool["--quiet"] && term.IsTerminal(os.Stderr.Fd()) {
bar := pb.New(0)
bar.SetUnits(pb.U_BYTES)
bar.ShowBar = false
bar.ShowSpeed = true
bar.Output = os.Stderr
bar.Start()
defer bar.Finish()
config.Stdout = io.MultiWriter(config.Stdout, bar)
}
config.Args[0] = "/bin/dump-flynn-redis"
return runJob(client, *config)
}
示例10: newPb
func newPb(size int) (bar *pb.ProgressBar) {
bar = pb.New(size)
bar.Current = barChar
bar.BarStart = ""
bar.BarEnd = ""
bar.Start()
return
}
示例11: Start
// Start starts showing progress
func (t *TextProgress) Start(pkg string, total float64) {
// TODO go to New64 once we update the pb package.
t.pbar = pb.New(0)
t.pbar.Total = int64(total)
t.pbar.ShowSpeed = true
t.pbar.Units = pb.U_BYTES
t.pbar.Start()
}
示例12: SetupResumeLog
//SetupResumeLog sets up ConnectionLog for a resumed download
func SetupResumeLog(filename string, length, noOfConn int) error {
connLog.stats = make([]ConnectionStat, noOfConn)
barArray := make([]*pb.ProgressBar, noOfConn+1)
totalbar := pb.New(length).Prefix("Total ")
lenSub := length / noOfConn
for i := 0; i < noOfConn; i++ {
partFilename := "temp/" + filename + "_" + strconv.Itoa(i)
if _, err := os.Stat(partFilename); err == nil {
reader, err := ioutil.ReadFile(partFilename)
if err != nil {
return err
}
header := reader[:16]
fileBegin := int(binary.LittleEndian.Uint64(header[0:8]))
fileEnd := int(binary.LittleEndian.Uint64(header[8:16]))
bar := pb.New(fileEnd - fileBegin).Prefix("Connection " + strconv.Itoa(i+1) + " ")
for j := 0; j < len(reader)-16; j++ {
bar.Increment()
totalbar.Increment()
}
customizeBar(bar)
connLog.stats[i] = ConnectionStat{connectionIndex: i, pbar: bar}
barArray[i] = bar
} else {
fileBegin := lenSub * i
fileEnd := lenSub * (i + 1)
if i == noOfConn-1 {
fileEnd = length
}
bar := pb.New(fileEnd - fileBegin).Prefix("Connection " + strconv.Itoa(i+1) + " ")
customizeBar(bar)
connLog.stats[i] = ConnectionStat{connectionIndex: i, pbar: bar}
barArray[i] = bar
}
}
customizeBar(totalbar)
connLog.totalbar = totalbar
barArray[noOfConn] = totalbar
var err error
connLog.pool, err = pb.StartPool(barArray...)
if err != nil {
return err
}
return nil
}
示例13: main
func main() {
runClean := flag.Bool("cleanup", false, "Cleanup merged branches")
noUpdate := flag.Bool("no-update", false, "Skip updating repositories")
flag.Parse()
if len(flag.Arg(0)) == 0 {
fmt.Println("ERROR: You have to specify the directory with repositiories to update.")
os.Exit(1)
}
errors := ""
u := api.Updater{}
u.DirHandler = &git.GitHandler{Dir: flag.Arg(0)}
if err := u.DirHandler.Prepare(); err != nil {
errors += fmt.Sprintf("Pre-update errors:\n%s", err)
}
bar := pb.New(len(u.DirHandler.Repositories()))
bar.ShowTimeLeft = false
bar.ShowSpeed = false
bar.Start()
completeFunc := func() error {
bar.Increment()
return nil
}
if !*noUpdate {
fmt.Fprintf(os.Stdout, "Updating repositories ...\n")
if err := u.DirHandler.Update(completeFunc); err != nil {
errors += fmt.Sprintf("Post-update errors:\n%s", err)
}
bar.FinishPrint(u.DirHandler.Summary())
}
if *runClean {
fmt.Fprintf(os.Stdout, "Cleaning up merged branches ...\n")
report := ""
for _, r := range u.DirHandler.Repositories() {
out, err := git.CleanMergedBranches(r, completeFunc)
if err != nil {
errors += fmt.Sprintf("\n%s\n", err)
} else {
report += fmt.Sprintf("\n%s:%s\n", r.Name(), out)
}
}
bar.FinishPrint(report)
}
if len(errors) > 0 {
fmt.Fprintf(os.Stderr, "%s", errors)
os.Exit(1)
}
}
示例14: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := args[0]
end := ""
if len(args) == 2 {
end = args[1]
}
if rangeConsistency == "l" {
fmt.Println("bench with linearizable range")
} else if rangeConsistency == "s" {
fmt.Println("bench with serializable range")
} else {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
results = make(chan result)
requests := make(chan v3.Op, totalClients)
bar = pb.New(rangeTotal)
clients := mustCreateClients(totalClients, totalConns)
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doRange(clients[i].KV, requests)
}
pdoneC := printReport(results)
go func() {
for i := 0; i < rangeTotal; i++ {
opts := []v3.OpOption{v3.WithRange(end)}
if rangeConsistency == "s" {
opts = append(opts, v3.WithSerializable())
}
op := v3.OpGet(k, opts...)
requests <- op
}
close(requests)
}()
wg.Wait()
bar.Finish()
close(results)
<-pdoneC
}
示例15: printStatus
func printStatus() {
count := cap(Buffers[0])
bar = pb.New(count)
bar.SetRefreshRate(100 * time.Millisecond)
bar.ShowCounters = true
bar.ShowTimeLeft = false
bar.Start()
}