Debian Codegraph @

example/full/full.go

raw
1 package main
2
3 import (
4 "fmt"
5 "math/rand"
6 "sync"
7 "time"
8
9 "github.com/gosuri/uiprogress"
10 "github.com/gosuri/uiprogress/util/strutil"
11 )
12
13 var steps = []string{
14 "downloading source",
15 "installing deps",
16 "compiling",
17 "packaging",
18 "seeding database",
19 "deploying",
20 "staring servers",
21 }
22
23 func main() {
24 fmt.Println("apps: deployment started: app1, app2")
25 uiprogress.Start()
26
27 var wg sync.WaitGroup
28 wg.Add(1)
29 go deploy("app1", &wg)
30 wg.Add(1)
31 go deploy("app2", &wg)
32 wg.Wait()
33
34 fmt.Println("apps: successfully deployed: app1, app2")
35 }
36
37 func deploy(app string, wg *sync.WaitGroup) {
38 defer wg.Done()
39 bar := uiprogress.AddBar(len(steps)).AppendCompleted().PrependElapsed()
40 bar.Width = 50
41
42 // prepend the deploy step to the bar
43 bar.PrependFunc(func(b *uiprogress.Bar) string {
44 return strutil.Resize(app+": "+steps[b.Current()-1], 22)
45 })
46
47 rand.Seed(500)
48 for bar.Incr() {
49 time.Sleep(time.Millisecond * time.Duration(rand.Intn(2000)))
50 }
51 }