-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
53 lines (46 loc) · 978 Bytes
/
utils.go
File metadata and controls
53 lines (46 loc) · 978 Bytes
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
package main
import "fmt"
func padLeft(str, pad string, length int) string {
if len(str) >= length {
return str
}
for {
str = pad + str
if len(str) > length {
return str[0:length]
}
}
}
func handleErr(err error, prefix string) {
if err != nil {
fmt.Println(prefix, ": ", err)
}
}
func getBytesFromUint16(source []byte, num uint16) {
source[0] = byte(num >> 8)
source[1] = byte(num)
}
func getBytesFromUint32(source []byte, num uint32) {
source[0] = byte(num >> 24)
source[1] = byte(num >> 16)
source[2] = byte(num >> 8)
source[3] = byte(num)
}
func getBytesFromUint64(source []byte, num uint64) {
source[0] = byte(num >> 56)
source[1] = byte(num >> 48)
source[2] = byte(num >> 40)
source[3] = byte(num >> 32)
source[4] = byte(num >> 24)
source[5] = byte(num >> 16)
source[6] = byte(num >> 8)
source[7] = byte(num)
}
func pos(slice []string, value string) int {
for p, v := range slice {
if v == value {
return p
}
}
return -1
}