-
Notifications
You must be signed in to change notification settings - Fork 19
/
common.go
73 lines (63 loc) · 1.45 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cmd
import (
"fmt"
"os"
"sync"
"gopkg.in/cheggaaa/pb.v1"
)
const (
ZCNStatusSuccess int = 0
ZCNStatusError int = 1
)
func (s *StatusBar) Started(allocationId, filePath string, op int, totalBytes int) {
s.b = pb.StartNew(totalBytes)
s.b.Set(0)
}
func (s *StatusBar) InProgress(allocationId, filePath string, op int, completedBytes int) {
s.b.Set(completedBytes)
}
func (s *StatusBar) Completed(allocationId, filePath string, filename string, mimetype string, size int, op int) {
// Not required
// s.b.PrependElapsed()
if s.b != nil {
s.b.Finish()
}
s.success = true
defer s.wg.Done()
fmt.Println("Status completed callback. Type = " + mimetype + ". Name = " + filename)
}
func (s *StatusBar) Error(allocationID string, filePath string, op int, err error) {
if s.b != nil {
s.b.Finish()
}
s.success = false
defer s.wg.Done()
PrintError("Error in file operation." + err.Error())
}
type StatusBar struct {
b *pb.ProgressBar
wg *sync.WaitGroup
success bool
}
type ZCNStatus struct {
walletString string
wg *sync.WaitGroup
success bool
errMsg string
}
func (zcn *ZCNStatus) OnWalletCreateComplete(status int, wallet string, err string) {
defer zcn.wg.Done()
if status == ZCNStatusError {
zcn.success = false
zcn.errMsg = err
zcn.walletString = ""
return
}
zcn.success = true
zcn.errMsg = ""
zcn.walletString = wallet
return
}
func PrintError(v ...interface{}) {
fmt.Fprintln(os.Stderr, v...)
}