-
Notifications
You must be signed in to change notification settings - Fork 13
/
helper.go
75 lines (62 loc) · 1.34 KB
/
helper.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
74
75
package helper
import (
"fmt"
)
//func RandStringBytes(n int, letters string) string {
// b := make([]byte, n)
// for i := range b {
// b[i] = letters[rand.Intn(len(letters))]
// }
// return string(b)
//}
func BoolToInt(b bool) int8 {
if b {
return 1
}
return 0
}
func ChunkSliceUint64(slice []uint64, chunkSize int) [][]uint64 {
var divided [][]uint64
for i := 0; i < len(slice); i += chunkSize {
end := i + chunkSize
if end > len(slice) {
end = len(slice)
}
divided = append(divided, slice[i:end])
}
return divided
}
func IsValidEnum(val string, enums map[string]string) bool {
if _, ok := enums[val]; ok {
return true
}
return false
}
func SliceUint64Difference(slice1 []uint64, slice2 []uint64) []uint64 {
var diff []uint64
// Loop two times, first to find slice1 strings not in slice2,
// second loop to find slice2 strings not in slice1
for i := 0; i < 2; i++ {
for _, s1 := range slice1 {
found := false
for _, s2 := range slice2 {
if s1 == s2 {
found = true
break
}
}
// String not found. We add it to return slice
if !found {
diff = append(diff, s1)
}
}
// Swap the slices, only if it was the first loop
if i == 0 {
slice1, slice2 = slice2, slice1
}
}
return diff
}
func ConvertUint64ToHex(serialNumber uint64) string {
return fmt.Sprintf("%0X", serialNumber)
}