-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelperFunctions.go
70 lines (62 loc) · 1.51 KB
/
HelperFunctions.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
package main
import (
"errors"
"fmt"
"os"
"strings"
)
var (
Black = Color("\033[1;30m%s\033[0m")
Red = Color("\033[1;31m%s\033[0m")
Green = Color("\033[1;32m%s\033[0m")
Yellow = Color("\033[1;33m%s\033[0m")
Purple = Color("\033[1;34m%s\033[0m")
Magenta = Color("\033[1;35m%s\033[0m")
Teal = Color("\033[1;36m%s\033[0m")
White = Color("\033[1;37m%s\033[0m")
)
func Color(colorString string) func(...interface{}) string {
sprint := func(args ...interface{}) string {
return fmt.Sprintf(colorString,
fmt.Sprint(args...))
}
return sprint
}
func arrayToString(a []uint8, delim string) string {
return strings.Trim(strings.Replace(fmt.Sprint(a), " ", delim, -1), "[]")
}
func IsContainedInUint32(slice []uint32, val uint32) bool { //a generic method to find out if a specific uint32 is contained in a slice of uint32
result := false
for i := 0; i < len(slice); i++ {
if slice[i] == val {
result = true
break
}
}
return result
}
func aspathtoIntSlice(aspath []uint32) []int {
aspathAsString := make([]int, len(aspath))
for i := 0; i < len(aspath); i++ {
aspathAsString[i] = int(aspath[i])
}
return aspathAsString
}
func min(a int, b int) int {
if a < b {
return a
} else {
return b
}
}
//seen on StackOverflow: https://stackoverflow.com/questions/12518876/how-to-check-if-a-file-exists-in-go
func Exists(name string) (bool, error) {
_, err := os.Stat(name)
if err == nil {
return true, nil
}
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
return false, err
}