17 Star 36 Fork 10

ShirDon-廖显东 / goProgressor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
full.go 964 Bytes
一键复制 编辑 原始数据 按行查看 历史
githubvip 提交于 2019-11-29 16:18 . commit
package main
import (
"fmt"
"math/rand"
"sync"
"time"
"gitee.com/shirdonl/goProgressor"
"gitee.com/shirdonl/goProgressor/util/strutil"
)
var steps = []string{
"downloading source",
"installing deps",
"compiling",
"packaging",
"seeding database",
"deploying",
"staring servers",
}
func main() {
fmt.Println("apps: deployment started: app1, app2")
goprogressor.Start()
var wg sync.WaitGroup
wg.Add(1)
go deploy("app1", &wg)
wg.Add(1)
go deploy("app2", &wg)
wg.Wait()
fmt.Println("apps: successfully deployed: app1, app2")
}
func deploy(app string, wg *sync.WaitGroup) {
defer wg.Done()
bar := goprogressor.AddBar(len(steps)).AppendCompleted().PrependElapsed()
bar.Width = 50
// prepend the deploy step to the bar
bar.PrependFunc(func(b *goprogressor.Bar) string {
return strutil.Resize(app+": "+steps[b.Current()-1], 22)
})
rand.Seed(500)
for bar.Incr() {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(2000)))
}
}
Go
1
https://gitee.com/shirdonl/goProgressor.git
git@gitee.com:shirdonl/goProgressor.git
shirdonl
goProgressor
goProgressor
master

搜索帮助