-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.go
63 lines (52 loc) · 1.07 KB
/
utility.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
package main
import (
"github.com/schollz/progressbar/v3"
"github.com/sirupsen/logrus"
"math/rand/v2"
"sync/atomic"
)
func shouldStop(f uint64, fCount *atomic.Uint64, odds float64) bool {
fCountLocal := fCount.Load()
if fCountLocal < f {
if stop := rand.Float64() <= odds; stop && fCount.CompareAndSwap(fCountLocal, fCountLocal+1) {
return true
}
}
return false
}
func progressAdd(bar *progressbar.ProgressBar, i int) {
if bar != nil {
_ = bar.Add(i)
}
}
func randomVi(n int) []V {
vi := make([]V, n)
for i := 0; i < n; i++ {
viRand := 0
if rand.Int()%2 == 0 {
viRand = 1
}
vi[i] = V(viRand)
}
return vi
}
type Logger struct {
verbose bool
}
type Fields map[string]interface{}
func (l *Logger) Init() {
if l.verbose {
logrus.SetLevel(logrus.DebugLevel)
}
}
func (l *Logger) Debug(fields map[string]interface{}, msg string) {
if l.verbose {
logrus.WithFields(fields).Debugln(msg)
}
}
func (l *Logger) Fatalln(args ...interface{}) {
logrus.Fatalln(args...)
}
func (l *Logger) Fatalf(s string, args ...interface{}) {
logrus.Fatalf(s, args...)
}